Convert System.Func <> to FastFunc <> to F #

When interacting with F # libraries from IronPython, it seems that the Python function object is not automatically converted to the standard F # FastFunc function object when passed to the F # interface, which takes the function as one of the parameters.

Python function objects, on the other hand, convert nicely to System.Func <> if the interface is one of them. That is, it is not easy to call from python:

 let myFunc (f: float->float) = f(3.5) 

and the following works fine:

 let myFunc2 (f: System.Func<float, float>) = f.Invoke(3.5) 

So my question is: if I want to be able to easily combine my Python function functions with F # functions, is there a way I can convert a System.Func <> object to a FastFunc object (to be able to have a thin interface to IronPython / C # etc, but be able to use the provided function as a regular F # function deeper in lib)?

Thanks Ricard

ps I don’t have enough reputation to create a new tag, maybe someone can create a FastFunc tag and flag this question if you find it appropriate

+4
source share
1 answer

Here:

  In order to convert from the Func delegate to the FastFunc, we use the FuncConvertExtensions class in the FSharp.PowerPack.Linq.dll assembly. 

From this site: http://codebetter.com/blogs/matthew.podwysocki/archive/2008/10/15/functional-c-implementing-async-computations-in-c.aspx

+3
source

All Articles