[Haskell-cafe] Parsec on TeX

Derek Elkins derek.a.elkins at gmail.com
Mon May 5 00:59:14 EDT 2008


On Sun, 2008-05-04 at 21:33 -0700, Ross Boylan wrote:
> On Sun, 2008-05-04 at 23:58 -0400, Brandon S. Allbery KF8NH wrote:
> > On 2008 May 4, at 23:40, Ross Boylan wrote:
> > 
> > > ERROR "grammar.hsl":21 - Type error in explicitly typed binding
> > > *** Term           : envEnd
> > > *** Type           : String -> GenParser Char a [Char]
> > > *** Does not match : String -> Parser ()
> > 
> > Hugs is prone to error messages that obscure the problem.  The trick  
> > here is to realize that the type "Parser ()" is the same as "GenParser  
> > Char a ()"; this then tells you that you have used a function that  
> > returns a [Char] (aka String) where a type () (Haskell's version of  
> > (void)) is expected.
> > 
> > > envEnd :: String -> Parser ()
> > > envEnd name = do{ reserved "\\end"
> > >                ; braces (string name)
> > >                }
> > 
> > 
> > Line 21 is "; braces (string name)"; it is producing a String, when  
> > you need a ().  One fix is to add one more line:
> > 
> >  > envEnd      :: String -> Parser ()
> >  > envEnd name =  do reserved "\\end"
> >  >                   braces (string name)
> >  >                   return ()
> > 
> > Another possible fix is to change the type of "envEnd" to "String ->  
> > Parser String"; this may depend on how it's used.
>  
> First, I'm really impressed with the fast and helpful responses from
> several people!
> 
> So the example is wrong?  What inference should I draw about the state
> of Parsec and its documentation?  I was thinking of trying Frost et al's
> X-SAIGA, but that the better documentation for parsec would be a plus.

Parsec is currently maintained, but wasn't maintained for quite a while
(admittedly, it didn't really require much maintenance; it was certainly
rampantly used during that time.)  Daan's paper on Parsec that you are
reading/read is probably the best tutorial-like introduction.  The
reference documentation has been Haddock-ed for the newer version of
Parsec (which you are almost certainly not using, but it is still very
similar.)

http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parsec.html

Unfortunately, Daan seems to have disappeared off of the face of the
internet so there isn't anything that can be done about fixing that
documentation (and likely that is in large part why this error is still
there.)



More information about the Haskell-Cafe mailing list