I have the following parsers functions
import Data.Char
type Parser a = String -> [(a,String)]
return' :: a -> Parser a
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
parse :: Parser a -> String -> [(a,String)]
parse p inp = p inp
(+++) :: Parser a -> Parser a -> Parser a
p +++ q = \inp -> case parse p inp of
[] -> parse q inp
[(v,out)] -> [(v,out)]
So far so good, they can be loaded into ghci. But when I add the following function
sat :: (Char -> Bool) -> Parser Char
sat p = do x <- item
if p x then return x else failure
I obtain an error. Could you tell what's going on?
return'notreturn.No instance for (Monad ((->) String) arising from a do statement