[Haskell-cafe] CFG specification and analysis directly in Haskell

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue Sep 27 14:58:58 CEST 2011

Anton Tayanovskyy wrote:
> As a weekend hack, I just realized that Haskell has this wonderful
> DoRec syntax that among other things seems to be able to let the user
> express context-free grammars together with their processing rules in
> normal Haskell code, without template Haskell or anything like that,
> just like parser combinators.
> I am just wondering if this is this a known and useful result? Are
> there libraries doing similar stuff?

John Meacham's frisby library [1] did something similar, though the 
technique is not as well-known as it should be.

Note that you don't need to give explicit names to your rules anymore, 
the monad can do that for you.

By the way, the old  mdo  notation was better suited to this task; the 
new  rec  notation has some problems in this regard that will hopefully 
be rectified soon.

   [1]: http://repetae.net/computer/frisby/#v%3AnewRule

Best regards,
Heinrich Apfelmus


More information about the Haskell-Cafe mailing list