That is correct, I did miss a closing parentheses.
But the program still won’t run in GHCi
and the error now is saying the following:
GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling MonadicParsingInHaskell ( MonadicParsingInHaskell.hs, interpreted )
MonadicParsingInHaskell.hs:12:10: error:
• No instance for (Applicative Parser)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monad Parser’
|
12 | instance Monad Parser where
| ^^^^^^^^^^^^
MonadicParsingInHaskell.hs:45:40: error:
• No instance for (MonadPlus Parser) arising from a use of ‘++’
• In the first argument of ‘parse’, namely ‘(p ++ q)’
In the expression: parse (p ++ q) cs
In the expression:
case parse (p ++ q) cs of
[] -> []
(x : xs) -> [x]
|
45 | p +++ q = Parser (\cs -> case parse (p ++ q) cs of
| ^^
Failed, no modules loaded.
I think the error is coming from this instance:
instance Monad Parser where
return :: a -> Parser a
return a = Parser (\cs -> [(a,cs)])
(>>=) :: Parser a -> (a -> Parser b) -> Parser b
p >>= f = Parser (\cs -> concat [parse (f a) cs' | (a,cs') <- parse p cs])
In particular I think it might be this line
"No instance for (Applicative Parser)" that is causing the errors. Though I don't exactly know what it means.