Hacker News new | ask | show | jobs
by michaelochurch 5259 days ago
Haskell: lazy and essentially pure. In Haskell, an Int is a lazy thunk that returns an Int, so if you write "a = 5 + 6" you're actually creating a thunk that will compute 5 + 6 if needed. For side effects, you use the IO monad and construct an IO Int, a type of a thunk that does I/O (all side effects are treated as IO) and returns an Int. Note that the Int can be evaluated once and its value stored, but the IO Int has to be evaluated again and again (because it may change, and if it's being eval'd multiple times that means we want to enact its side effects multiple times).

Ocaml: strict and impure if needed, but has everything you need to write great functional code (and not much more, which makes Ocaml actually fun to read; I can't say the same of that horror they call C++). I tend to think of it as a functional C. It's a bare-bones, simple language but it's awesome.

Haskell uses type classes for what Ocaml achieves more generally (but also with more work) with functors. Type classes are prettier. Functors handle complex cases (multiple related types) better. Hard call which is "better".

Haskell is more mind-blowing, Ocaml is more practical for most purposes, but probably not as practical as Scala. I like them both (and Scala).

Sadly, I wouldn't bet on either reaching the mainstream. Haskell is lazy, which makes it really hard to reason about memory usage. Ocaml's a great language, but the libraries available are quite poor and the effort to get it ready for multicore is DOA. I wish these languages have more of a future than I think they actually do. Now we're in the "raiding phase" where languages like Scala are borrowing awesomeness from them just like Ruby and Python did to Lisp 15 years ago.

On that, I think Scala's actually a good bet for the next 5 years, and not a bad language at all, although it's hard to learn because most of the online resources are pretty poor. (Odersky's Scala book is great.)