[Haskell-cafe] Parsec - separating Parsing from Lexing

Stephen Tetley stephen.tetley at gmail.com
Mon Nov 30 11:58:26 EST 2009

Hi Fernando

Which version of Parsec are you using, the one that ships with GHC or Parsec 3?

I would imagine whichever you one you are using you have the imports
wrong for these modules:

import Text.Parsec.Pos
import Text.Parsec.Prim

should be ...

import Text.ParserCombinators.Parsec.Pos
import Text.ParserCombinators.Parsec.Prim

Also it seems like an applicative instance for Parsec's GenParser
monad is missing. This isn't defined for parsec-, people seem
to define it themselves:

-- The Applicative instance for every Monad looks like this.
instance Applicative (GenParser s a) where
    pure  = return
    (<*>) = ap

... you will need `ap` from Control.Monad in scope.

Also there is a pdf document for Parsec (should be available from Daan
Leijen's home page) that covers separate scanners, it has quite a lot
more documentation than Parsec's Haddock docs.

For semantic analysis I'd highly recommend UUAG, it is well documented
and used for a large compiler (EHC). There is also a version of Andrew
Appel's Tiger language written with it that is much smaller and more
comprehensible, the version on Hackage doesn't seem to contain the
attribute grammar source but it is available here:



Best wishes


More information about the Haskell-Cafe mailing list