I get the impression that you are trying to attract MonadErrorfor the wrong reason.
try (many1 parser1) <|> parser2 , , try <|> - , . , , (many1 parser1) >> parser2, ? ( (many1 parser1), >>= (many1 parser1) parser2.)
(: , , , , ... , () , t .)
ParsecT/MonadError. , , , , OP , , , , .
-, , , Parsec MonadError. - , , - ; ParsecT MonadError , , MonadError . GHCi:
> :i Parsec
type Parsec s u = ParsecT s u Identity
-- Defined in Text.Parsec.Prim
-- no MonadError instance
instance (MonadError e m) => MonadError e (ParsecT s u m)
-- Defined in Text.Parsec.Prim
-- this explains why the above is the case
-- (a ParsecT-created monad will only become an instance of MonadError through
-- this instance, unless of course the user provides a custom declaration)
, catchError ParsecT. GHCi:
> (runParserT (char 'a' >> throwError "some error") () "asdf" "a" :: Either String (Either ParseError Char)) `catchError` (\e -> Right . Right $ 'z')
Right (Right 'z')
(, , , , ). GHC :
Either String (Either ParseError Char)
, - Either ParseError Char - Either String Identity. Either String MonadError, throwError/catchError, , catchError, , , . , .
. . ret, :
forall (m :: * -> *) a.
(Monad m) =>
m (Either [Char] (Either ParseError a))
( GHCi... , {-# LANGUAGE NoMonomorphismRestriction #-}, .)
- - ret. :
> runParserT ret () "asdf" "a"
Right (Left "some error")
, , catchError, unexpected, , , ( ) ... , , - .