The code is as below:
type Parser a = String -> [(a, String)]
retrn :: a -> Parser a
retrn v = \inp -> [(v, inp)]
parse :: Parser a -> String -> [(a, String)]
parse p inp = p inp
item :: Parser Char
item = \inp -> case inp of
[] -> []
(x:xs) -> [(x, xs)]
--problem code
p :: Parser (Char, Char)
p = do x <- item
item
y <- item
retrn (x, y)
It gives the following type error:
SO-34035520.hs:19:8:
Couldn't match type `[(Char, String)]' with `Char'
Expected type: String -> [((Char, Char), String)]
Actual type: Parser ([(Char, String)], [(Char, String)])
In a stmt of a 'do' block: retrn (x, y)
In the expression:
do { x <- item;
item;
y <- item;
retrn (x, y) }
What noteworthy is, the sample code that is on official website of the book can be interpreted smoothly, which is *.lhs format.
So, can somebody tell me why? I've been working on this struggle for days.
Thanks in advance.