我可以在 F# 中使用动态类型吗?
.net4.0
mytest.py
def Add (a, b):
return a+b
我可以在 C# 4 中使用它,如下所示:
ScriptRuntime runtime = Python.CreateRuntime();
dynamic script = runtime.UseFile("mytest.py");
Console.WriteLine(script.Add(1, 3));
但是,如何在 F# 中使用动态?
open System
open Microsoft.Scripting.Hosting
open IronPython.Hosting
let call a b=
let runtime = Python.CreateRuntime()
let script = runtime.UseFile("mytest.py")
script.Add(a,b)
.net4.0
mytest.py
def Add (a, b):
return a+b
I can use it in C# 4, like this:
ScriptRuntime runtime = Python.CreateRuntime();
dynamic script = runtime.UseFile("mytest.py");
Console.WriteLine(script.Add(1, 3));
But, how can I use dynamic in F#?
open System
open Microsoft.Scripting.Hosting
open IronPython.Hosting
let call a b=
let runtime = Python.CreateRuntime()
let script = runtime.UseFile("mytest.py")
script.Add(a,b)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nuget上有一个模块FSharp.Interop.Dynamic,它实现了动态使用 dlr 的操作员。所以:
与许多现有的片段相比,它有几个优点。
添加 !?前缀运算符来处理直接调用动态对象和函数,您在运行时没有该类型。
它是开源的,Apache许可证,你可以查看实现,它包括单元测试 示例案例。
There is a module FSharp.Interop.Dynamic, on nuget that implements the dynamic operator using the dlr. So That:
It has several advantages over a lot of the snippets out there.
Adds an !? prefix operator to handle invoking directly dynamic objects and functions you don't have the type at runtime.
It's open source, Apache license, you can look at the implementation and it includes unit test example cases.