[Haskell-cafe] Still no joy with parsec
Derek Elkins
derek.a.elkins at gmail.com
Tue May 6 13:44:50 EDT 2008
On Tue, 2008-05-06 at 09:52 -0700, Ross Boylan wrote:
> 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 )
>
> g.hs:11:19:
> 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.
Look at the expression.
> 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?
Look at your code.
> Source:
> 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