与 IronPython 中的 F# 库交互时,当传递到接受函数作为参数之一的 F# 接口时,Python 函数对象似乎不会自动转换为标准 F# FastFunc 函数对象。
另一方面,Python 函数对象很好地转换为 System.Func<> 。如果接口是其中之一。
也就是说,这不容易从 python 调用:
let myFunc (f: float->float) =
f(3.5)
而以下代码可以完美地工作:
let myFunc2 (f: System.Func<float, float>) =
f.Invoke(3.5)
所以我的问题是,如果我希望能够轻松地提供我的 F# 函数 Python 函数对象,是否有某种方法可以将 System.函数<>对象到 FastFunc 对象(能够拥有与 IronPython/C# 等的精简接口,但能够将提供的函数用作库中更深层次的常规 F# 函数)?
谢谢,
里卡德
PS
我没有足够的代表来创建新标签,也许有人可以创建一个 FastFunc 标签,并用它来标记这个问题(如果您认为合适)
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
发布评论
评论(1)
此处:
从此站点: http://codebetter.com/blogs/matthew.podwysocki/archive/2008/10/15/tical-c-implementing-async-computations-in-c.aspx
Here:
From this site: http://codebetter.com/blogs/matthew.podwysocki/archive/2008/10/15/functional-c-implementing-async-computations-in-c.aspx