[Haskell-cafe] Parsing Haskell in Parsec

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Mon Mar 21 17:28:32 CET 2011


Alex Rozenshteyn <rpglover64 <at> gmail.com> writes:

> as part of a larger project of porting 
> http://www.cs.jhu.edu/~scott/pl/book/dist/  from ocaml to Haskell.

Nice idea. I was using a similar approach (interpreters for
various semantic domains) in a course on semantics(+ compilation).

I modelled it after the Turbak/Gifford book
http://mitpress.mit.edu/catalog/item/?ttype=2&tid=11656
(in fact after the book had been praised in this here mailing list,
about two years ago).

In fact the contents of these two books seem largely similar,
and the following remark holds true:

Using Haskell as an implementation language, you get a very nice addition: 
you can model the semantics domains by Monads, and it's very natural, 
(Identity monad = naive interpreter, Maybe monad = for exceptions e.g. division 
by zero, State monad = for assignment, Continuation passing monad = 
for CPS style programming). 

Now, neither of the books dare to use the M-word.
Although Turbak is really  "doing monads": he is clearly
defining several "bind" and "return", he's just not naming them as such.

You may browse my source code (quite unpolished) here
http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=ws10-cb/.git;a=tree
and there's a parser as well (in the Exp directory).

I'd be happy to get comments on my code as well.
Would it look better with Monad transformers?
And there's some amount of (tree walking) boilerplate
that could perhaps be replaced by some template haskell magic.
But then, magic is no good in teaching...

Best regards, J.W.





More information about the Haskell-Cafe mailing list