tags:

views:

1117

answers:

3

What sets the two ML dialects apart?

A: 

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

Charlie Martin
+25  A: 

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.

  • 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 interfaces (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.

Norman Ramsey
very informative! my +1 for this.
eriawan
You forgot equality (unrestricted and unsafe in OCaml vs safe but restricted equality types in SML), non-generalized type variables ('_a in OCaml), printf, interpretation of file names as module names in OCaml, far more currying in OCaml's stdlib. You wrote interface twice when you meant something else (implementation?) the second time.
Jon Harrop
and OCaml's or-patterns and guards in pattern matching.
Jon Harrop
+11  A: 

For details regarding the syntactic differences that Norman Ramsey mentioned, here are a couple of web pages:

bk1e