@@ -1,3 +1,4 @@
1+{-# LANGUAGE UndecidableInstances #-}
12#include "inline.hs"
23
34-- |
@@ -139,6 +140,9 @@ where
139140import Control.Applicative (Alternative(..), liftA2)
140141import Control.Exception (assert, Exception(..))
141142import Control.Monad (MonadPlus(..), (>=>))
143+import Control.Monad.IO.Class (MonadIO, liftIO)
144+import Control.Monad.Reader.Class (MonadReader, ask, local)
145+import Control.Monad.State.Class (MonadState, get, put)
142146import Control.Monad.Catch (MonadCatch, try, throwM, MonadThrow)
143147import Data.Bifunctor (Bifunctor(..))
144148import Fusion.Plugin.Types (Fuse(..))
@@ -1121,3 +1125,25 @@ instance MonadCatch m => MonadPlus (Parser m a) where
11211125
11221126 {-# INLINE mplus #-}
11231127 mplus = alt
1128+
1129+instance (MonadThrow m, MonadReader r m, MonadCatch m) => MonadReader r (Parser m a) where
1130+ {-# INLINE ask #-}
1131+ ask = fromEffect ask
1132+ {-# INLINE local #-}
1133+ local f (Parser step init' extract) =
1134+ Parser ((local f .) . step)
1135+ (local f init')
1136+ (local f . extract)
1137+
1138+
1139+instance (MonadThrow m, MonadState s m) => MonadState s (Parser m a) where
1140+ {-# INLINE get #-}
1141+ get = fromEffect get
1142+ {-# INLINE put #-}
1143+ put = fromEffect . put
1144+
1145+
1146+instance (MonadThrow m, MonadIO m) => MonadIO (Parser m a) where
1147+ {-# INLINE liftIO #-}
1148+ liftIO = fromEffect . liftIO
1149+