4 ms·
The obvious example is a compiler. Java, C, Python and Javascript all lack algebraic datatypes and pattern matching, which make writing a compiler much easier.
by sgeisenh 10y ago
The obvious example is a compiler.
Java, C, Python and Javascript all lack algebraic datatypes and pattern matching, which make writing a compiler much easier. There are many additional features of Haskell that make it especially good for implementing a compiler, if you know what you're doing.
I guess that's cheating because a compiler is just a function from source language to target language, so it is easily expressed in a functional language. But it does answer the question nicely.
- galacticpony 10y agoI believe you're mistaking "easy" with "convenient".
- sgeisenh 10y agoHow so? Pattern matching makes for more readable code. And more readable code makes writing projects easier. It is also more convenient to write code using pattern matching, but that isn't the primary benefit.
- galacticpony 10y agoThis is a superficial view of readability, focusing on terseness and perceived syntactical elegance. "True" readability is achieved through a consistent structuring of your program, which has to conform to the expectations of the reader. Programmers must first build this expectation from picking up patterns in the code, which emerge no matter if you use pattern matching or an equivalent structure using the available language constructs.
- joesb 10y agoThey all contribute to readability. You can always write in assembly code, with all that consistent structuring and conforming to expectation. But I'll takes writing in higher language with "abstraction you can write yourself" any day.
- deleted 10y ago[deleted]
- eudox 10y agoAlgebraic 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.
- knucklesandwich 10y agoNot 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/Compilers_and_interpreters https://wiki.haskell.org/Applications_and_libraries/Compiler...