What sets the two ML dialects apart?
OCaml adds object-orientation features and has some minor syntax differences.
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 typety
unifies with the type ofe
. In SML,e : ty
is accepted only if the typety
is an instance of the type ofe
. 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.
For details regarding the syntactic differences that Norman Ramsey mentioned, here are a couple of web pages:
- Comparing Objective Caml and Standard ML: has good explanations of the differences, and the "practical" vs. "pure" icons are amusing too
- Standard ML and Objective Caml, Side by Side