在 C# 中使用 F# 作为 dll
是否可以将 F# 项目用作 C# 项目中的程序集?
如果是;由于F#在计算方面比C#更快(不是吗?),如果代码的计算部分在F#中,而主项目在C#中,是否会使应用程序更快?
Is it possible to use an F# project as an assembly in a C# project?
If yes; as F# is faster than C# for calculation stuffs (isn't it?), if the calculation part of the code is in F# and the main project is in C#, does it make the application faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,可以将 F# 项目用作 C# 项目中的程序集。
不,F# 本身并不比 C# 快。两者都被编译成相同类型的中间语言并由相同的.net框架运行。您也许能够使用 F# 的某些特定功能来编写比 C# 更优雅的快速算法,但这在很大程度上取决于算法。
Yes, it's possible to use an F# project as an assembly in a C# project.
No, F# is not per se faster than C#. Both are compiled into the same type of Intermediate Language and run by the same .net Framework. You might be able to use some specific feature of F# to write a fast algorithm more elegantly than you would in C#, but that depends highly on the algorithm.
是的,F# 是一种 .NET 语言,并将提供兼容的 dll
F# 并不更快。 F# 提供了一种更好的方式来表达某些类型的问题。因此,它减少了错误数量并提高了生产力。 F# 还大力鼓励无状态、更具可扩展性并明确分离数据和函数的编程模型。
Yes, F# is a .NET language and will provide a compliant dll
F# is not faster. F# provides a better way of expressing certain types of problems. It therefore reduces amounts of bugs and increases productivity. F# also greatly encourages a programming model that is stateless, more scalable and gives a clear separation of data and functions.
是的,你可以,而且这是有道理的。我个人在我的项目中使用这种方法。
但使用 F# 而不是 C# 表达计算这一事实并不意味着您的代码会运行得更快或更慢。
当然,如果你熟悉函数式编程,你会以更简洁和优雅的方式编写更快的计算代码,这也将使你可以轻松地测试、维护和推理你的代码。
Yes, you can and it makes sense. I personally use that approach in my projects.
But the fact that you express a calculation in F# instead of C# doesn't mean that your code will run faster or slower.
Of course, if you are familiar with functional programming you'll write faster your calculation code and in a more concise and elegant way, which will also allow you to test, maintain and reason about your code easily.