let sub (a:float[]) (b:float[])=
[| for i = 0 to Array.length a - 1 do yield a.[i]-b.[i] |]
let fx t = [0..t]
let x=sub (fx t) (fx t)
Above compiles OK.
But the same causes an error when I replace the function call with a method invocation:
type type_f = delegate of float -> float[]
let mutable f =new type_f(fun t->[|0..t|])
let m=f.Invoke(5) //float[]
let y=sub m f.Invoke(5)//error
How do I pass the result of a method invocation as a parameter to a function?
In F#, the line
ambiguously parses as
(passing three arguments to
sub).To fix this, you need more parentheses:
(Note that using
delegatetypes is not idiomatic unless interoperating with .NET code in other languages. Iffwas a function, thenwould be sufficient, as you have noted.)