Live data from Hacker News

Write You a Haskell: Building a modern functional compiler from first principles

dev.stephendiehl.com

11–20 of 48 posts

Re: Write You a Haskell: Building a modern functional compiler from first principles

#11
post #7
post #5

Now this is very interesting! There are plenty of compiler writing tutorials for conservative, imperative programming languages with a straightforward static type system (like C). I did study a little bit of compilers for functional languages from Simon Peyton-Jones' old book "The Implementation of Functional Programming Languages" [0]. It predates the Haskell programming language and uses a contemporary research lan…

I think the online version of that book actually uses Haskell (but the text still refers to Miranda).

I don't think so, but Miranda and Haskell are very alike so it's easy to be mistaken.

Re: Write You a Haskell: Building a modern functional compiler from first principles

#13
I recommend Lisp In Small Pieces (LISP) by Christian Queinnec and Compiling with Continuations by Andrew Appel if you're interested in writing a functional compiler. Also:

http://matt.might.net/articles/cps-conversion/

http://lucacardelli.name/Papers/BasicTypechecking.pdf

http://library.readscheme.org/page1.html

https://research.microsoft.com/pubs/67083/spineless-tagless-...

http://www.pipeline.com/~hbaker1/CheneyMTA.html

Re: Write You a Haskell: Building a modern functional compiler from first principles

#14
post #13

I recommend Lisp In Small Pieces (LISP) by Christian Queinnec and Compiling with Continuations by Andrew Appel if you're interested in writing a functional compiler. Also: http://matt.might.net/articles/cps-conversion/ http://lucacardelli.name/Papers/BasicTypechecking.pdf http://library.readscheme.org/page1.html https://research.microsoft.com/pubs/67083/spineless-tagless-... http://www.pipeline.com/~hbaker1/CheneyMTA…

For the interested, I have implemented Cardelli's paper here: https://github.com/noteed/mojito/blob/master/Language/Mojito...

Re: Write You a Haskell: Building a modern functional compiler from first principles

#15
post #7
post #5

Now this is very interesting! There are plenty of compiler writing tutorials for conservative, imperative programming languages with a straightforward static type system (like C). I did study a little bit of compilers for functional languages from Simon Peyton-Jones' old book "The Implementation of Functional Programming Languages" [0]. It predates the Haskell programming language and uses a contemporary research lan…

I think the online version of that book actually uses Haskell (but the text still refers to Miranda).

That seems like an easy mistake to make from what I remember in reading the origin of Haskell. They had issue with the licensing and cost of Miranda and struck out to build upon it. Here's the original article, "A History of Haskell: Being Lazy With Class"[0]

[0]: http://research.microsoft.com/en-us/um/people/simonpj/Papers...

Re: Write You a Haskell: Building a modern functional compiler from first principles

#16
post #4

To pull this forward, the author is also the author of "Implementing a JIT Compiled Language in Haskell and LLVM" [0]. [0] http://www.stephendiehl.com/llvm/

If you haven't spent time with this, you need to stop everything and look at it. It's wonderful.

Re: Write You a Haskell: Building a modern functional compiler from first principles

#17
post #16
post #4

To pull this forward, the author is also the author of "Implementing a JIT Compiled Language in Haskell and LLVM" [0]. [0] http://www.stephendiehl.com/llvm/

If you haven't spent time with this, you need to stop everything and look at it. It's wonderful.

Wonderful regarding learning using LLVM? I mean, isn't the heavy lifting (most interesting part?) done by LLVM, so you're just using it?

I haven't read it, that's why I'm asking this.

Re: Write You a Haskell: Building a modern functional compiler from first principles

#18
post #17
post #16

Earlier quoted context omitted.

If you haven't spent time with this, you need to stop everything and look at it. It's wonderful.

Wonderful regarding learning using LLVM? I mean, isn't the heavy lifting (most interesting part?) done by LLVM, so you're just using it? I haven't read it, that's why I'm asking this.

So there is a basic introduction to generating LLVM in Haskell there, but what's so great about it is that generating a lexer/parser/(interpreter|compiler) is almost magic in Haskell. The total code of that project is remarkably small. For that reason, it's a pretty standard Haskell workflow to do everything in Haskell and then have it emit LLVM/Cuda/whatever to do the heavy-lifting, and then you get to reason in Haskell and your back-end takes care of the rest. As much as that sounds complicated, it's really, really not.

Re: Write You a Haskell: Building a modern functional compiler from first principles

#19
post #17
post #16

Earlier quoted context omitted.

If you haven't spent time with this, you need to stop everything and look at it. It's wonderful.

Wonderful regarding learning using LLVM? I mean, isn't the heavy lifting (most interesting part?) done by LLVM, so you're just using it? I haven't read it, that's why I'm asking this.

Think of it as a template for this new essay. Of all of the hard optimization work occurring, most of it is embedded in LLVM. But the process of going from stringly syntax to intermediate language to back-end compilation is an important journey and doing it as Steven does using Haskell is an elegant way to scope out those steps.

Re: Write You a Haskell: Building a modern functional compiler from first principles

#20
post #13

I recommend Lisp In Small Pieces (LISP) by Christian Queinnec and Compiling with Continuations by Andrew Appel if you're interested in writing a functional compiler. Also: http://matt.might.net/articles/cps-conversion/ http://lucacardelli.name/Papers/BasicTypechecking.pdf http://library.readscheme.org/page1.html https://research.microsoft.com/pubs/67083/spineless-tagless-... http://www.pipeline.com/~hbaker1/CheneyMTA…

In addition to Compiling with Continuations, I found Compiling with Continuations, Continued by Andrew Kennedy very useful, as well.

http://research.microsoft.com/pubs/64044/compilingwithcontin...

Post reply on HN