functional parser type error

Hi. I'm Following the book of Programming in haskell written by Graham Hutton. In Chapter number 8 there is a discussion about functional parsers and it is defined a functional Parser item and some basic parsers as follow *success :: a -> Parser a* *success v = \ inp -> [(v,inp)]* *failure :: Parser a* *failure = \inp -> [ ]* *item :: Parser Char* *item = \inp -> case inp of* *[ ] -> [ ]* *(x:xs) -> [(x,xs)]* Based on this parser it is defined a* *new parser called *sat p* *sat :: (Char -> Bool ) -> Parser Char* *sat p = do x <- item* *if p x then success x else failure* as result, this error appears *Couldn't match expected type `Char'* *with actual type `[(Char, String)]'* *In the first argument of `p', namely `x'* *In the expression: p x* *In the expression: if p x then success x else failure* Can you help me ? Greets, Felipe

On Mon, Apr 02, 2012 at 09:58:31PM +0100, felipe zapata wrote:
Hi.
I'm Following the book of Programming in haskell written by Graham Hutton. In Chapter number 8 there is a discussion about functional parsers and it is defined a functional Parser item and some basic parsers as follow
How is the Parser type defined? The problem may be that you need to make Parser a newtype, and write a Monad instance for it -- if Parser is defined as a type synonym, then there will be a default Monad instance used (the one for functions) but that is not the one you want. -Brent
participants (2)
-
Brent Yorgey
-
felipe zapata