SML 和 OCaml 有什么区别?

发布于 2024-07-15 11:47:49 字数 1436 浏览 9 评论 0原文

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

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

发布评论

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

评论(2

屌丝范 2024-07-22 11:47:49

有很多差异,一些是技术性的,一些是社会政治性的。 我试图把更重要的差异放在第一位。

  • SML 是一种有定义和标准的语言。 它是稳定的(事实上已被冻结,因此无法进化)。 Objective Caml 是由 INRIA 的一个小组控制的实现。 它继续发展。 (在我看来,演变得到了很好的管理。)

  • SML 有许多实现; Caml 只有一个。

  • Objective Caml 有许多附加功能,其中最突出的可能是对象和多态变体。

  • 这两种语言具有截然不同的记录类型模型。 简而言之,在Caml中,记录字段的名称必须是唯一的,而在SML中,同一范围内的两个不同记录类型可以具有共同的字段名称。 这种怪癖可能会使从 SML 移植到 Caml 有点棘手。

  • 存在相当多的语法差异。

  • 库和标准函数有很大不同。 Caml 库非常必要,而 SML 标准基础库功能性更强。 例如,函数组合是SML中的顶级原语; 它不是 Caml 库的一部分。 Caml 字符串库不提供折叠函数(至少从版本 3.08 开始不提供)。 许多 Caml List 函数的实现对于很长的列表来说是不安全的; 他们摧毁了堆栈。

  • 类型系统略有不同:在 Caml 中,如果类型 ty 统一,则接受表达式 e : ty 上的类型注释类型为e。 在 SML 中,仅当类型 tye 类型的实例时,才接受 e : ty。 这种区别使得 Caml 中的注释在实践中用处不大,因为不可能使用类型注释来坚持表达式是多态的。

  • Caml 在接口(称为模块类型签名)和(具体)实现(称为模块)之间具有更加理智和合理的关系或结构)而不是SML。 在 SML 中几乎任何事情都会发生,你必须依靠程序员来建立良好的约定。 在 Caml 中,编译器建立并强制执行良好的约定。

  • 在 SML 中,算术运算符被重载以应用于浮点和整数数据。 在 Caml 中,运算符不会重载; 浮点运算符用额外的点表示。

  • 在SML中,程序员可以控制中缀运算符的优先级和结合性。 在 Caml 中,这些由操作员姓名的第一个字符确定。 此限制限制了能够定义自己的中缀表示法的好处。

如需更详细的分析以及编辑评论,您还可以查看Adam Chlipala 的比较页面

There are lots of differences, some technical, some sociopolitical. I've tried to put more important differences first.

  • SML is a language with a definition and a standard. It is stable (and in fact has been frozen so it cannot evolve). Objective Caml is an implementation controlled by a small group at INRIA. It continues to evolve. (IMO the evolution is managed well.)

  • SML has many implementations; Caml has just one.

  • Objective Caml has a number of additional features, among which the most prominent are probably objects and polymorphic variants.

  • The two languages have dramatically different models of record types. Briefly, in Caml, names of record fields must be unique, where in SML, two different record types in the same scope may have field names in common. This quirk can make porting from SML to Caml a bit tricky.

  • There are quite a few syntactic differences.

  • The libraries and standard functions are dramatically different. The Caml library is very imperative, whereas the SML Standard Basis Library is more functional. For example, function composition is a top-level primitive in SML; it's not part of the Caml library. The Caml string library doesn't provide a fold function (at least not as of version 3.08). Implementations of many of the Caml List functions are unsafe for very long lists; they blow the stack.

  • The type systems are subtly different: In Caml, a type annotation on an expression e : ty is accepted if the type ty unifies with the type of e. In SML, e : ty is accepted only if the type ty is an instance of the type of e. This distinction renders the annotation in Caml much less useful in practice, because it is impossible to use a type annotation to insist that an expression is polymorphic.

  • Caml has a much more sane and sensible relationship between interfaces (called module types or signatures) and (concrete) implementations (called modules or structures) than SML. In SML pretty much anything goes and you have to rely on the programmer to establish good conventions. In Caml, good conventions are established and enforced by the compiler.

  • In SML, arithmetic operators are overloaded to apply to both floating-point and integer data. In Caml, operators are not overloaded; floating-point operators are notated with an extra dot.

  • In SML, the programmer can control the precedence and associtivity of infix operators. In Caml, these are determined by the first character of the operator's name. This restriction limits the benefits of being able to define your own infix notation.

For a more detailed analysis complete with editorial comment, you could also look at Adam Chlipala's comparison page.

荆棘i 2024-07-22 11:47:49

OCaml 添加了面向对象的功能,并且有一些细微的语法差异。

OCaml adds object-orientation features and has some minor syntax differences.

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