Very interested in seeing how he'll deal with lexing Haskell. It's a major pain, tools like Parsec are very good out of the box with whitespace insensitivity, but not whitespace sensitive stuff.
Write You a Haskell: Building a modern functional compiler from first principles
31–40 of 48 posts
Re: Write You a Haskell: Building a modern functional compiler from first principles
#32Very interested in seeing how he'll deal with lexing Haskell. It's a major pain, tools like Parsec are very good out of the box with whitespace insensitivity, but not whitespace sensitive stuff.
I suppose using haskell-src-exts is cheating...
I jest, but this is an issue I've thought about idly for a while. Maybe it's possible to write a two-step parser: one that turns chars into tokens (and cheat a little bit by stripping spaces in some contexts to make it context free), and then you have a nice CFG that you can do easily.
Re: Write You a Haskell: Building a modern functional compiler from first principles
#33Very interested in seeing how he'll deal with lexing Haskell. It's a major pain, tools like Parsec are very good out of the box with whitespace insensitivity, but not whitespace sensitive stuff.
Re: Write You a Haskell: Building a modern functional compiler from first principles
#34As a sidenote, Stephen is also the author/maintainer of "What I Wish I Knew When I Was Learning Haskell"[0] which is a great resource both for those who are learning and for slightly advanced programmers. [0] http://dev.stephendiehl.com/hask/
Re: Write You a Haskell: Building a modern functional compiler from first principles
#35Earlier quoted context omitted.
I suppose using haskell-src-exts is cheating...
"I will build haskell by taking the source code and running it" I jest, but this is an issue I've thought about idly for a while. Maybe it's possible to write a two-step parser: one that turns chars into tokens (and cheat a little bit by stripping spaces in some contexts to make it context free), and then you have a nice CFG that you can do easily.
Re: Write You a Haskell: Building a modern functional compiler from first principles
#36As a sidenote, Stephen is also the author/maintainer of "What I Wish I Knew When I Was Learning Haskell"[0] which is a great resource both for those who are learning and for slightly advanced programmers. [0] http://dev.stephendiehl.com/hask/
Your comment implies that programmers stop learning once they are slightly advanced.
Re: Write You a Haskell: Building a modern functional compiler from first principles
#37Now 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…
Re: Write You a Haskell: Building a modern functional compiler from first principles
#38Very interested in seeing how he'll deal with lexing Haskell. It's a major pain, tools like Parsec are very good out of the box with whitespace insensitivity, but not whitespace sensitive stuff.
https://github.com/purescript/purescript/blob/master/src/Lan...
The state is defined in https://github.com/purescript/purescript/blob/master/src/Lan...
(its just the column number). I believe the whitespace rules for Haskell are somewhat subtle, but shouldn't be much harder.
Re: Write You a Haskell: Building a modern functional compiler from first principles
#39I'd like to recommend The Programming Language Zoo by Andrej Bauer. It is a collection of programming language implementations, small and clear, written in OCaml. http://andrej.com/plzoo/
Re: Write You a Haskell: Building a modern functional compiler from first principles
#40Very interested in seeing how he'll deal with lexing Haskell. It's a major pain, tools like Parsec are very good out of the box with whitespace insensitivity, but not whitespace sensitive stuff.
IIRC, Haskell has a well-defined mapping of whitespace to explicit braces and semicolons -- I suppose one could perform that transform first to desugar, then parse the resulting token stream normally...