FS0003 when overriding operators
-
Tuesday, March 19, 2013 7:53 PM
Hello. I'm writing an optimization program using Rosenbrock methods - http://en.wikipedia.org/wiki/Rosenbrock_methods
So i'm trying to describe relations between scalar and vector, so i'm writing a code like this
[<EntryPoint>]
let main argv =
let ( *? ) (a:float, vector:float[]) =
vector |> Array.map (fun x->x * a)
let (+?) (a:float, vector:float[]) =
vector |> Array.map (fun x->x + a)
let (+%) (X:float[], Y:float[]) =
Array.map2(fun x y -> x + y) X Y
let n = 2
let d = Array.init n (function i -> (Array.init n (function index -> if index = i then 1. else 0.)))
let x : float[] = Array.zeroCreate n
let y = x
let k, j = 1, 1
let f (x : float[]) = x.[0]**2.
let fu lambda = f(y +% (lambda *? d.[1]))
printfn "%A" argv
0but there's an error FS0003:
This value is not a function and cannot be applied
in
let fu lambda = f(y +% (lambda *? d.[1]))
how to fix it?
All Replies
-
Wednesday, March 20, 2013 12:27 AM
When you create custom infix operators you probably should use curried form of function definition:
let ( *? ) (a:float) (vector:float[]) = vector |> Array.map (fun x->x * a) let ( +? ) (a:float) (vector:float[]) = vector |> Array.map (fun x->x + a) let ( +% ) (X:float[]) (Y:float[]) = Array.map2(fun x y -> x + y) X Y
Otherwise compiler doesn't know how to call infix operator with tupled input.Petr
- Marked As Answer by PsilonRus Wednesday, March 20, 2013 5:03 AM
-
Wednesday, March 27, 2013 11:49 PM
Hi PsilonRus and Petr Plepilov.
This may interest you:
http://fsharpnews.blogspot.com/2011/01/gradient-descent.htmlI'm working on "Refolding Planar Polygons" by Iben, O'Brien and Demaine.
Climbing the learning curve of optimization.
And the state of .NET maths ...
FSharp.Math -> Math.Net -> Math.Numerics -> Cloud Numerics
I'm not sure I got that right ...Solvers too.
I'm interested in your progress.
Thanks. PLH OOE Art
Peace Love Happiness PLH Only One Earth OOE