[Haskell-cafe] Parsec on TeX

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Sun May 4 23:58:52 EDT 2008


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.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list