Bug in Parser Combinators?
Erik Zuurbier
F.S.A.Zuurbier@inter.nl.net
Sun, 23 Nov 1997 18:29:53 +0100
Nick,
I ran your parser program. I had to take <@ out of the definition of digit
to prevent a compile error. After that, the program ran fine.
I found two differences between your version of the Parsers and the one
as I copied it from the book. First, your definition of <*>:
<*> :: (Parser s a) -> Parser s [a]
<*> p = (p <:&> <*> p)
Mine:
<*> :: (Parser s a) -> Parser s [a]
<*> p = p <:&> <*> p <|> succeed []
Your definition of satisfy:
satisfy :: (s -> Bool) -> Parser s s
satisfy f = p
where
p [x:xs]
| f x = [(xs, x)]
| otherwise = []
Mine:
satisfy :: (s->Bool) (s->t) -> Parser s t
satisfy f g = p
where p [x:xs] | f x = [(xs,g x)]
p _ = []
You don't have a provision for empty input lists.
Your taking out (s->t) and leaving it to <@ may be a good idea,
I don't know. But it explains why I had to take out <@ to run your program.
I am not going to analyse why this causes your error.
But if you just copy the book as is, there is no problem.
Certainly, I cannot back your suggestion that there is a bug
in the BOOK.
Regards Erik Zuurbier