I'm in chapter 8 of Graham Hatton's program at Haskell, and I copy the code and test it in the GHC.
See the slides here: http://www.cis.syr.edu/~sueo/cis352/chapter8.pdf in particular slide 15
Relevant code that I have copied so far:
type Parser a = String -> [(a, String)]
pih_return :: a -> Parser a
pih_return v = \inp -> [(v, inp)]
failure :: Parser a
failure = \inp -> []
item :: Parser Char
item = \inp -> case inp of
[] -> []
(x:xs) -> [(x,xs)]
parse :: Parser a -> String -> [(a, String)]
parse p inp = p inp
sat :: (Char -> Bool) -> Parser Char
sat p = do x <- item
if p x then pih_return x else failure
I changed the name of the function returnfrom the book to pih_returnso that it does not collide with the Prelude function return.
Errors are in the last function sat. I copied this directly from the book.
As you can see, it pis a function from Charto Bool(for example, isDigit) and xhas a type [(Char, String)], so the first error.
pih_return v [(v, inp)], inp String. sat, v x, Char.
, inp sat
sat :: (Char -> Bool) -> Parser Char
sat p inp = do x <- item inp
if p (fst x) then pih_return (fst x) inp else failure inp
?