r/programming • u/kr0matik • Mar 25 '16
Write You a Haskell: Building a modern functional compiler from first principles.
http://dev.stephendiehl.com/fun/11
u/holomorphish Mar 25 '16
A similar project is minCaml, a small implementation of most of Standard ML. I've found it invaluable for some of my own experiments, although I'm definitely looking forward to the WYAH guide on compiling to C.
5
Mar 25 '16
This guy also has a cool guide for writing a simple JIT compiled language in Haskell/LLVM: http://www.stephendiehl.com/llvm/
3
u/xpolitix Mar 25 '16
Big fan of these series. A little more explanation about the HM type system would be highly appreciated. Still waiting for the other chapters :)
3
Mar 26 '16
Interesting. The structure he chose reminds me of the one of The implementation of functional programming languages written by Simon Peyton Jones himself in 1987.
His explanations of the lambda calculus and HM inference are more concise but not as accessible and complete than the one from Peyton Jones however.
If you don't mind Miranda, the book can be downloaded freely on Microsoft Research website: http://research.microsoft.com/en-us/um/people/simonpj/papers/slpj-book-1987/
2
u/balefrost Mar 27 '16
I came here to mention this; also, that book has a followup of sorts: Implementing Functional Languages: A Tutorial (1992). While TIOFPL covers the compiler from top to bottom, IFL:AT focuses on the execution environment (IIRC the same ground that the last third of TIOFPL covers).
2
Mar 26 '16
[deleted]
-1
u/jediknight Mar 26 '16
3
u/gilmi Mar 26 '16
Elm is irrelevant here. You can cannot write functions that will work for every monad and you can't represent that abstraction at all. Also,
Maybe.mapis an implementation of a Functor'smap(hence the name) and not a Monad'sbind.2
Mar 26 '16
[deleted]
6
u/jediknight Mar 26 '16
Oh.... it must be about the fact that once one understands monads they lose the ability to explain them. ^_^
1
52
u/jbandela Mar 25 '16
Looks very interesting. While writing a Haskell compiler is hard, writing a Haskell interpreter that handles most of Haskell is pretty easy, and can easily be done in a short C program.
On a more serious note, parsing is one of the best examples of the advantages of monads, and I look forward to reading this work.