开发者

Converting a System.Func<> to a FastFunc<> in F#

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开发者_如何学JAVA# 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜