I have a c# dll library with one method g accepting the following function f in C# as an input
void f(double[] x, ref double func, double[] grad, object obj)
In the function body, both func and grad values are updated. The input signature of g(f) in F# reads
f:float[]-> byref<float> -> float[]-> obj->unit
how can I write f in f# to use g(f) in f#?
EDIT when I follow ildjarn’s answer below like
let f(x:float[]) (func:byref<float>) (grad:float[]) (obj: obj) =
func <- ...
grad.[0] <- ...
grad.[1] <- ...
...
()
I got error on g(f) with
This function value is being used to construct a delegate type whose signature includes a byref argument. You must use an explicit lambda expression taking 4 arguments.
what should I do to make it work? thanks.
UPDATE: it turns out I have to use g(fun (x:float[]) (func:byref<float>) (grad:float[]) (obj: obj) -> .... Cannot give the inside function a name like f.
1 Answer