Hacker News new | ask | show | jobs
by eudox 3606 days ago
Algebraic data types and pattern matching are equivalent to having a class hierarchy and implementing the same method for each class.

The idea that Haskell or OCaml or SML are specially suited for compiler writing is a nineties truism that is thrown around a lot, never backed by any evidence whatsoever.

1 comments

Not true: class hierarchies aren't closed, which means you can't check exhaustivity of cases (or you can, but you can't guarantee exhaustivity with dynamically loading code and you generally destroy your chances of having incremental compilation). That's a huge advantage of patterns and ADTs. Scala offers a sort of compromise to this with "sealed" traits/classes, but this is pretty uncommon (and doesn't provide any advantages over ADTs IMO). Also in practice, I think there's a huge advantage to languages with explicit pattern support in terms of how much boilerplate gets cut out.

Also I'm not aware of any research into why they're better (I'm not a PLT researcher, so I wouldn't be aware of papers like that), but a huge amount of languages are originally written in ML derived languages. Here's a list of ones just written in haskell: https://wiki.haskell.org/Applications_and_libraries/Compiler...