3 ms·
Nowadays, OCaml has so many more syntactic sugar and typing goodies compared to SML, that it's not fair to compare them anymore. I'm no expert in SML, but from
by c-cube 9y ago
Nowadays, OCaml has so many more syntactic sugar and typing goodies compared to SML, that it's not fair to compare them anymore. I'm no expert in SML, but from what I know:
- OCaml's pattern matching is more powerful (more or-patterns, lazy, matching records with field-puning):
`match x with lazy {x; y; z=(None | Some 0); _} -> x+y`
- GADTs along with phantom types: many things are now type-safe (including the builtin format strings)
- inline records in sum types: `type 'a tree = Empty | Node of { left: 'a tree; mutable key: 'a; right: 'a tree; }`
also, I prefer `let x = y in …` rather than SML's equivalent which forces nesting because of the final `end`.
In addition, flambda generates very good code. I don't know if it's as good as MLTon, but it's definitely an improvement.
(edit: formatting)
- hajile 9y agoOcaml is a mess. Just like C++, PHP, or Perl, it's spent way too much time bolting extra stuff here and there until different codebases can look like completely different languages. Ocaml's features don't flow well together and make it very hard to teach the language (as used in the real world) to new developers. Golang has fewer features than Ocaml and is worse in almost every way, but people love it's simplicity. The best language features are the ones you can add without significantly increasing syntactic complexity. I agree that Ocaml has some great features that the current SML spec lacks. That spec is 20 years old now. There's plenty of room to look at Ocaml features and pick a good set that does enough of the things without blowing up the complexity. SML's let expression is definitely superior to Ocaml's. Ocaml has two different `let` expressions -- one for top-level and one for sub-expressions. To borrow from a comparison [here](http://adam.chlipala.net/mlcomp/ http://adam.chlipala.net/mlcomp/) (* Ocaml *) let six = 6 let rec fact x = if x = 0 then 1 else x * fact (x - 1) let six_fact = let six = 6 in let rec fact x = if x = 0 then 1 else x * fact (x - 1) in fact 6 (* SML *) val six = 6 fun fact x = if x = 0 then 1 else x * fact (x - 1) val six_fact = let val six = 6 fun fact x = if x = 0 then 1 else x * fact (x - 1) in fact 6 end SML groups multiple declarations together which provides greater clarity IMO while having an end keyword helps identify the let block.
- ernst_klim 9y ago>Ocaml's features don't flow well together May you provide an example of features which don't flow well together?