Let's build a compiler (in Haskell): Part 5 - Doing it with Types
posted by Geoff Ford on 29 Jan 2010
Up until now, I have been doing a near direct translation of Crenshaws tutorial to Haskell. After reading Andersons paper Parsing with Haskell I realised that Haskell has a very powerful Type system for a reason.
Defining the Types
So let's take a step back and rework what has been done so far using Types and we'll see how much easier, extensible and safer it is to use.
First of all a recap of our language elements we have defined so far.
<expression> ::= <term>[<addop><term>]*
<term> ::= <factor>[<mulop><factor>]*
<factor> ::= <number>
And translating that into ...
