F# 更改为 OCaml

发布于 2024-07-06 03:10:19 字数 1833 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懵少女 2024-07-13 03:10:19

这个问题已经回答了一段时间了,但令我感到非常惊讶的是,大多数答案都说 F# 中缺少哪些 OCaml 功能 - 如果您想将现有的 OCaml 程序移植到 F#(这可能是大多数参考文章的动机)。 然而,有许多功能使 F# 成为一种不同的语言(不仅仅是用于 .NET 的 OCaml 的有限版本!)以下是 F# 中添加的一些功能:

  • 度量单位 使用引用对处理数值计算的代码进行类型检查
  • 元编程(这使得在 F# 中使用 LINQ 成为可能,并且对于 WebSharper 平台等有前景的项目也至关重要)
  • 活动模式 用于为函数数据类型创建抽象(对于更复杂的模式匹配应用程序来说通常非常有用)
  • 计算表达式,这是异步工作流背后的语言功能(一个用于异步 I/O/Web 服务/GUI 编程)
  • .NET 兼容对象系统,使得与 .NET 平台完全互操作成为可能(OCaml 也支持对象,但有所不同 - 有当然这两个系统都有一些好处)。
  • 重载运算符 - 据我所知,OCaml 没有重载运算符 - 在 F# 中,您可以对所有数字类型以及支持它的类型使用 +

老实说,我认为 Visual Studio IDE 也值得一提。 这不是语言的一部分,但它确实改善了用户体验(Visual Studio 中的 IntelliSense 支持真的很好!)

如果你看一下列表,有很多东西很大程度上促进了 F# 的流行,所以它很多不仅仅是“没有函子的 OCaml”。 F# 绝对基于 OCaml(并借鉴了 Haskell 等其他语言的思想),并与它们共享许多方面,但也有很多其他的东西。 我猜想,如果没有异步工作流程、.NET 风格的 OO 和元编程之类的东西,Microsoft 开发人员部门永远不会将 F# 包含在 Visual Studio 2010 中。

This question has been answered for some time now, but I was quite surprised that most of the answers say what OCaml features are missing in F# - this is definitely good to know if you want to port existing OCaml programs to F# (which is probably the motivation of most of the referenced articles). However, there are many features that make F# a different language (not just a limited version of OCaml for .NET!) Here is a couple of things that are added in F#:

  • Units of measure that allow you to type-check code dealing with numerical calculations
  • Meta-programming using quotations (which makes it possible to use LINQ in F# and is also essential for promissing projects like the WebSharper platform)
  • Active patterns for creating abstractions for functional data types (and generally very useful feature for more complicated pattern matching applications)
  • Computation expressions which is a language feature behind asynchronous workflows (a library for asynchronous I/O/web service/GUI programming)
  • .NET compatible object-system that makes it possible to fully interoperate with the .NET platform (OCaml also has a support for objects but different - there are of course some benefits in both of the systems).
  • Overloaded operators - As far as I know, OCaml doesn't have overloaded operators - in F# you can use + for all numeric types as well as your types that support it.

And, honestly, I think that it is also worth mentioning the Visual Studio IDE. This is not a part of the language, but it really improves the user experience (IntelliSense support in Visual Studio is really good!)

If you look at the list, there are many things that largely contributed to the popularity of F#, so it's much more than just "OCaml without functors". F# is definitely based on OCaml (and takes ideas from other languages such as Haskell) and shares many aspects with them, however there is also a lot of other things. I guess that without things like asynchronous workflows, .NET style OO and meta-programming, the Microsoft Developer Division would never include F# in Visual Studio 2010.

jJeQQOZ5 2024-07-13 03:10:19

主要区别在于 F# 不支持:

  • 函子
  • OCaml 样式
  • 对象多态变体
  • camlp4/5 预处理器或扩展点 (ppx)

此外,F# 对于标记参数和可选参数具有不同的语法。

理论上,不使用这些功能的 OCaml 程序可以使用 F# 进行编译。 学习 OCaml 是对 F# 的完美合理的介绍(我想反之亦然)。

完整的差异列表是 此处(注意:archive.org 替换了死链接)。

The main differences are that F# does not support:

  • functors
  • OCaml-style objects
  • polymorphic variants
  • the camlp4/5 preprocessor or extension points (ppx)

In addition, F# has a different syntax for labeled and optional parameters.

In theory, OCaml programs that don't use these features can be compiled with F#. Learning OCaml is a perfectly reasonable introduction to F# (and vice versa, I'd imagine).

The complete list of differences is here (note: archive.org replacement of dead link).

纵山崖 2024-07-13 03:10:19

F# 和 OCaml 在分类学上属于 ML 语言家族,其中还包括一整套其他奇怪的动物。 F# 比 OCaml 更新,并且它没有任何一个函子 [模块的函数 -> ] 模块]或行类型[对象类和多态变体]。 对于在 .Net 平台上进行开发的人来说,这两种简化可能会使学习曲线变得更容易。 遗憾的是,这两种语言功能在 OCaml 中非常强大,因此阅读 OCaml 文献来深入了解如何为 F# 编写代码可能会导致过早地对后者感到沮丧,因为它可能是 C# 的绝佳替代品(两者都可用)。

F# and OCaml are taxonimically classes in the ML family of languages, which includes a whole passle of other weird animals too. F# is newer than OCaml, and it doesn't have either functors [functions of module -> module] or row types [object classes and polymorphic variants] yet. Between them, those two simplifications probably make the learning curve easier for someone developing on the .Net platform. Sadly, those two language features are hugely powerful in OCaml, so reading the OCaml literature to gain insights into how to code for F# will probably lead to premature frustration with the latter when it's probably an excellent alternative to C# where both are available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文