[Haskell-cafe] Still no joy with parsec

Ross Boylan RossBoylan at stanfordalumni.org
Tue May 6 12:52:11 EDT 2008

I kept getting parse failures when I ran my little Parsec TeX snippet on
a sample code.  Seeing that ghc6.8 had debugging, I upgraded to it, only
to discover that I can't even get the code to compile.

$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :load g
[1 of 1] Compiling Main             ( g.hs, interpreted )

    Couldn't match expected type `t1 -> GenParser Char () t'
           against inferred type `CharParser st ()'
    In the expression: reserved "\\begin" 1
    In a 'do' expression: reserved "\\begin" 1
    In the expression:
        do reserved "\\begin" 1
           braces (many1 letter)
Failed, modules loaded: none.

Do parsec and 6.8 just not get along?

More generally, how can I go about diagnosing such problems?  Since I
can't load it, I can't debug it or get :info on the types.

It looks as if maybe it's expecting a Monad, but getting a parser.  But
I don't know why that would have changed vs using 6.6.

More questions about the error messages.  Where is the expected type,
and where is the inferred type, coming from?  I'm guessing the expected
type is from the function signature and the position inside a do (or
perhaps from the argument following the ; in the do?) and the inferred
type is what I would just call the type of reserved "begin".

And what is the 1 that appears after 'reserved "\\begin"'?  An indicator
that all occurrences of the text refer to the same spot in the program?
Nesting level?


P.S.  There have been some issues with the Debian packaging of ghc6.8,
so it's possible I'm bumping into them.  I thought/hoped the problems
were limited to non i386 architectures.  Also, I'm pretty sure that the
parsec code used by ghc6.6, ghc6.8, and hugs is all in different files.
So conceivably the parsec source differs.  I have ghc6 6.8.2-5 and

import Text.ParserCombinators.Parsec
import qualified Text.ParserCombinators.Parsec.Token as P
import Text.ParserCombinators.Parsec.Language(haskell)
reserved = P.reserved haskell
braces = P.braces haskell

-- TeX example

envBegin :: Parser String
envBegin     = do{ reserved "\\begin"
1                 ; braces (many1 letter)

More information about the Haskell-Cafe mailing list