What sets the two ML dialects apart?
2 Answers
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 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 (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.

- 198,648
- 61
- 360
- 533
-
5You 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. – J D Dec 12 '09 at 04:20
-
1
-
1Note that the limitation on the usefulness of type annotations has been alleviated somewhat in 3.12, where annotating `e : 'a . ty(a)` is possible and meaningful. – Apr 18 '11 at 00:42
-
4You make the important observation: "Caml library is very imperative". This seems to permeate the whole philosophy, up to the point that parallel implementation on multicore hardware seems to be very difficult to impossible. In contrast, there are at least two parallel SMLs: Mlton and Poly/ML. – Makarius Oct 09 '13 at 22:07
-
2About your third point, record names don't require uniqueness anymore in OCaml. – PatJ Feb 27 '15 at 01:56
-
"*It is stable (and in fact has been frozen so it cannot evolve)*": Is it an official decision by the language designers? Google and Wikipedia didn't help me finding any links on this matter. – Anton Trunov Apr 20 '16 at 20:16
-
2Sorry, it looks like I got this topic closed. Questioning the closings appears to be taboo too: https://meta.stackoverflow.com/questions/355729/is-there-a-specific-rule-that-says-that-comparing-languages-is-off-topic – MWB Aug 26 '17 at 23:47
OCaml adds object-orientation features and has some minor syntax differences.

- 110,348
- 25
- 193
- 263