What are the differences between SML and OCaml?

What distinguishes two dialects of ML?

+84
sml ocaml ml
Mar 31 '09 at 1:19
source share
3 answers

There are many differences, some technical, some socio-political. At first I tried to make more important differences.

  • SML is a language with definition and standard. It is stable (and actually frozen, so it cannot develop). Caml's goal is an implementation controlled by a small group at INRIA. He continues to evolve. (IMO evolution is well-managed.)

  • SML has many implementations; Caml has only one.

  • The Caml lens has a number of additional functions, among which the most noticeable are probably objects and polymorphic options.

  • In two languages, there are completely different models of record types. In short, in Caml, record field names must be unique, where in SML two different types of records in the same field can have common field names. This quirk can make porting from SML to Caml a little more difficult.

  • There are quite a few syntactic differences.

  • Libraries and standard features are very different. The Caml library is very important, while the core SML library is more functional. For example, the composition of functions is a top-level primitive in SML; It is not part of the Caml library. The Caml string library does not provide a bend function (at least not starting with version 3.08). Implementations of many Caml List functions are unsafe for very long lists; they explode the stack.

  • Type systems are very different: in Caml, a type annotation in an e : ty expression is accepted if ty combined with type e . In SML, e : ty accepted only if type ty is an instance of type e . This difference makes Caml annotation much less useful in practice because it is not possible to use type annotation to insist that an expression is polymorphic.

  • Caml has a much more reasonable and reasonable relationship between interfaces (called module types or signatures) and (specific) implementations (called modules or structures) than SML. Almost everything goes in SML, and you have to rely on the programmer to establish good conventions. In Caml, good conventions are set and executed by the compiler.

  • In SML, arithmetic operators are overloaded to apply to both floating and integer data. In Caml, operators are not overloaded; Floating point operators are indicated by an extra dot.

  • In SML, a programmer can control the priority and associativity of infix operators. In Caml, they are defined by the first character of the operator name. This limitation limits the benefits of being able to define your own infix notation.

For a more detailed analysis, supplemented by an editorial comment, you can also see the Adam Khlipala comparison page .

+139
Mar 31 '09 at 2:00
source share

For more on the syntax differences that Norman Ramsey mentioned, here are a few web pages:

+29
Mar 31 '09 at 2:46
source share

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

-5
Mar 31 '09 at 1:35
source share



All Articles