F # function to be used in C # library: delegate of type byref

I have a C # dll library with one method gaccepting the following function fin C # as input

 void f(double[] x, ref double func, double[] grad, object obj)

The values โ€‹โ€‹of funcand are updated in the function body grad. Input signature g(f)in F # reads

f:float[]-> byref<float> -> float[]-> obj->unit

how can i write fin f # for use g(f)in f #?

EDIT when I follow ildjarn below for example

let f(x:float[]) (func:byref<float>) (grad:float[]) (obj: obj) = 
    func <- ...
    grad.[0] <- ... 
    grad.[1] <- ...
    ...
    ()

I got an error on g(f)using

This function value is used to construct a delegate type whose signature includes the byref argument. You must use an explicit lambda expression with four arguments.

, ? . : , g(fun (x:float[]) (func:byref<float>) (grad:float[]) (obj: obj) -> .... f.

+3
2
let function1 (x:double[], func:byref<double>, grad:double[], obj:obj) = ...
+1

F # .NET - , , . LChart ():

Excel .NET - , F #, .NET. , API. , FSharp.Core.dll dll, F #.

Update:

ref double func f # let y = ref (func), double[] grad float[] F #. . ref:

public class tt
{
    public static void temp(int x, ref double[] y)
    {
        y = new double[10];
        y[1] = 10;
    }
}

F #:

    let y = ref (Array.create 10 0.0)
    tt.temp(0, y)
    printfn "%A" y
    0

, temp ref. ref , ref F #.

+1

All Articles