I have defined a F# function in my VB code as follow:
Dim g As Microsoft.FSharp.Core.FSharpFunc(Of Double, Double)
How can I assign g to a particular function: for example I want g(x) = x^2?
What is the syntax for it in VB.NET ?
In addition to what Reed says, the FSharp.Core library actually defines a helper method that will turn a delegate (which you can create using lambdas) into an F# function.
You can find it in FuncConvert.ToFSharpFunction see MSDN for more info. I would recommend using this function over creating a custom class, because it relies less on internal details of how the F# compiler compiles functions (you still need to know about the FSharpFunc type, but not as much...)
I don't know much about VB, but I suppose something like this might work:
Dim g = FuncConvert.ToFSharpFunction(Function(x As Double) x * x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With