
I am new to Haskell and Parsec, and am trying to understand both. I tried to follow the example of how to use Parsec to parse TeX begin/end groups, but can't get it to run. I'm using HUGS -98 on Debian. When I copied the code I got errors about unknown terms (reserved and braces). I've tried to get them from the lexer, but now get this error :load grammar.hsl ERROR "grammar.hsl":21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String -> GenParser Char a [Char] *** Does not match : String -> Parser () Can anyone help me understand what the problem is? Here's the code the caused the above error; I believe the part after --TeX example is verbatim from the Parsec documentation. I picked haskell as the language for to lexer "arbitrarily." 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 environment = do{ name <- envBegin ; environment ; envEnd name } <|> return () envBegin :: Parser String envBegin = do{ reserved "\\begin" ; braces (many1 letter) } envEnd :: String -> Parser () envEnd name = do{ reserved "\\end" ; braces (string name) }

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@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

allbery:
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.
Yeah, if you're on Debian it would make sense to install GHC -- its much more active, much faster, and supports more things. It's well maintained on Debian too. -- Don

apfelmus wrote:
Don Stewart wrote:
Yeah, if you're on Debian it would make sense to install GHC -- its much more active, much faster, and supports more things. [than Hugs]
Except for compile and load time, Hugs is really fast there.
Mmm, possibly. I seem to recall it being instantaneous on my old AMD K6 500MHz with both Hugs and GHCi. But it was a while ago... Certainly only Hugs as the nice feature of automatically reloading your source every time you hit save. I really miss that in GHCi. [OTOH, if you're going to do this, expect lots of "hey, this doesn't parse!" type messages. undefined is your friend!]

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. I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter. Thanks.

I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter.
GHCi makes a great exploratory tool (and then you have the option of compiling the code as well). There are some nice integration tools with emacs and vim, but its also good to gain familiarity with ghci, the online documentation on haskell.org, and perhaps even drop by the #haskell IRC channel. Cheers, Don

On 2008 May 5, at 0:14, Ross Boylan wrote:
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.
The original documentation which you will probably find via Google is several years out of date; unfortunately, nobody has updated it and the newer API documentation lacks most of the actual details of how to *use* Parsec --- so really you need to have daan's Parsec paper and the Haskell library API documentation ( http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserComb... ) open at the same time to see how things have changed. I will note that a newer version of Parsec is in development; I am hoping it will have somewhat better documentation (preferably an updated version of the original Parsec paper).
I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter.
ghci (the interpreter component of GHC) works much like hugs but is much more up to date; there are a number of useful libraries which either haven't been ported to or simply don't work with Hugs. (The new Parsec is one of these, as it works with the ByteString library (much faster than standard Strings, which are naive linked lists of characters); ByteString really needs to be compiled and Hugs is only an interpreter.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

I will add one more comment: perhaps the biggest thing Haskell has going for it has nothing to do with the language itself; as you noticed, it's the community. One might expect to find crusty mathematicians and dubiously social geeks(*), but in fact the Haskell community is one of the friendliest and most helpful I've encountered anywhere. (*) ironically, the person saying this is both dubiously social and an even crustier system administrator :) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

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-Parse... 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.)

On Sun, 2008-05-04 at 23:59 -0500, Derek Elkins wrote:
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.)

On Sun, 2008-05-04 at 23:57 -0700, Ross Boylan wrote:
On Sun, 2008-05-04 at 23:59 -0500, Derek Elkins wrote:
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.)
I'm not sure that he is still at Microsoft; I've heard tell that he is off on another pursuit. At any rate, I've tried three different email addresses including the one listed there and have not gotten a response and others have had trouble getting in touch with him as well. I guess I could try calling that number and see what happens...

On Mon, 2008-05-05 at 07:56 -0500, Derek Elkins wrote:
On Sun, 2008-05-04 at 23:57 -0700, Ross Boylan wrote:
On Sun, 2008-05-04 at 23:59 -0500, Derek Elkins wrote:
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.)
I'm not sure that he is still at Microsoft; I've heard tell that he is off on another pursuit. At any rate, I've tried three different email addresses including the one listed there and have not gotten a response and others have had trouble getting in touch with him as well. I guess I could try calling that number and see what happens...
The last publication listed is March 2008, so it looks pretty current. Ross

Ross Boylan wrote:
First, I'm really impressed with the fast and helpful responses from several people!
Ask an easy question and you'll get at least a dozen people tripping over each other in their rush to offer you useful advice. Ask a hard question, or an uninteresting question, and enjoy the utter silence... :-( Still, I suppose that's not *too* surprising.
I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter.
I used to use Hugs as well. Then I updated to the newest version, and found it horrifically buggy. That's when I moved over to GHC. As Don said, GHCi doesn't let you define new functions like Hugs does, but other than that it's far more useful. (And actually, you *can* define small functions using 'let'. It's just awkward.) Best thing is, you can compile your code with GHC, and then load that compiled code into GHCi so it runs at near-native speed. And of course, the latest version of GHCi now comes with an actual debugger. And GHC-compiled binaries have a profiler. And... [This was a while ago; maybe Hugs has been updated again since I last looked. Certainly Hugs is smaller to download, and more friendly to use than GHC. But it just doesn't have the same power...]

andrewcoppin:
Ross Boylan wrote:
First, I'm really impressed with the fast and helpful responses from several people!
Ask an easy question and you'll get at least a dozen people tripping over each other in their rush to offer you useful advice. Ask a hard question, or an uninteresting question, and enjoy the utter silence... :-( Still, I suppose that's not *too* surprising.
I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter.
I used to use Hugs as well. Then I updated to the newest version, and found it horrifically buggy. That's when I moved over to GHC. As Don said, GHCi doesn't let you define new functions like Hugs does, but
Other way around, GHCi lets you define new functions, unlike Hugs :) $ ghci Prelude> let f x = x ^ 2 Prelude> f 2 4 And: $ hugs Type :? for help Hugs.Base> let f x = x ^ 2 ERROR - Syntax error in expression (unexpected end of input) Hugs.Base> [Leaving Hugs]

On Sun, 2008-05-04 at 20:40 -0700, Ross Boylan wrote:
I am new to Haskell and Parsec, and am trying to understand both. I tried to follow the example of how to use Parsec to parse TeX begin/end groups, but can't get it to run. I'm using HUGS -98 on Debian.
When I copied the code I got errors about unknown terms (reserved and braces). I've tried to get them from the lexer, but now get this error :load grammar.hsl ERROR "grammar.hsl":21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String -> GenParser Char a [Char] *** Does not match : String -> Parser ()
Can anyone help me understand what the problem is?
Here's the code the caused the above error; I believe the part after --TeX example is verbatim from the Parsec documentation. I picked haskell as the language for to lexer "arbitrarily."
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 environment = do{ name <- envBegin ; environment ; envEnd name } <|> return ()
envBegin :: Parser String envBegin = do{ reserved "\\begin" ; braces (many1 letter) }
envEnd :: String -> Parser () envEnd name = do{ reserved "\\end" ; braces (string name) }
braces returns, in this case, a string, so the type of envEnd is String -> Parser String. You can either change the type and add a return () to environment after envEnd or add a return () to envEnd.

On Mon, May 5, 2008 at 3:40 AM, Ross Boylan
I am new to Haskell and Parsec, and am trying to understand both. I tried to follow the example of how to use Parsec to parse TeX begin/end groups, but can't get it to run. I'm using HUGS -98 on Debian.
When I copied the code I got errors about unknown terms (reserved and braces). I've tried to get them from the lexer, but now get this error :load grammar.hsl ERROR "grammar.hsl":21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String -> GenParser Char a [Char] *** Does not match : String -> Parser ()
Can anyone help me understand what the problem is?
Here's the code the caused the above error; I believe the part after --TeX example is verbatim from the Parsec documentation. I picked haskell as the language for to lexer "arbitrarily."
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 environment = do{ name <- envBegin ; environment ; envEnd name } <|> return ()
envBegin :: Parser String envBegin = do{ reserved "\\begin" ; braces (many1 letter) }
envEnd :: String -> Parser () envEnd name = do{ reserved "\\end" ; braces (string name) }
My guess is the following: string :: String -> Parser String braces :: Parser a -> Parser a Meaning braces (string name) :: Parser String Which is not the same as your declared return type Parser (). Add a return () at the end of envEnd.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (8)
-
Andrew Coppin
-
apfelmus
-
Brandon S. Allbery KF8NH
-
Brandon S.Allbery KF8NH
-
Derek Elkins
-
Don Stewart
-
Luke Palmer
-
Ross Boylan