views:

247

answers:

1

Hello!

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

On the other hand, the Python function objects are nicely converted to System.Func<> if the interface is one of these. That is, this is not easily callable from python:

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

while the following works perfectly:

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

So my question is, if I want to be able to easily feed my F#-functions Python function objects, is there some way that 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 supplied function as a regular F# function deeper in the lib)?

Thanks, Rickard

ps I haven't enough rep to create a new tag, maybe someone could create a FastFunc tag and tag this question with it if you find it appropriate

+3  A: 

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

Tony
Thank you, that worked perfectly. Great!
Rickard