@@ -9,6 +9,7 @@
9module Control.Monad.Trans.Ether.Reader where
9module Control.Monad.Trans.Ether.Reader where
11import Data.Proxy (Proxy(Proxy))
11import Data.Proxy (Proxy(Proxy))
12+import Data.Functor.Identity (Identity(..))
12import Data.Coerce (coerce)
13import Data.Coerce (coerce)
13import Control.Applicative (Alternative)
14import Control.Applicative (Alternative)
14import Control.Monad (MonadPlus)
15import Control.Monad (MonadPlus)
@@ -30,6 +31,8 @@ newtype EtherReaderT tag r m a = EtherReaderT (R.ReaderT r m a)
30 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
31 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
31 , MonadFix, MonadTrans, MonadIO )
32 , MonadFix, MonadTrans, MonadIO )
34+type EtherReader tag r = EtherReaderT tag r Identity
33instance Monad m => MonadEther (EtherReaderT tag r m) where
36instance Monad m => MonadEther (EtherReaderT tag r m) where
34 type EtherTags (EtherReaderT tag r m) = tag ': EtherTags m
37 type EtherTags (EtherReaderT tag r m) = tag ': EtherTags m
@@ -39,6 +42,9 @@ etherReaderT _proxy = EtherReaderT . R.ReaderT
39runEtherReaderT :: proxy tag -> EtherReaderT tag r m a -> r -> m a
42runEtherReaderT :: proxy tag -> EtherReaderT tag r m a -> r -> m a
40runEtherReaderT _proxy (EtherReaderT (R.ReaderT s)) = s
43runEtherReaderT _proxy (EtherReaderT (R.ReaderT s)) = s
45+runEtherReader :: proxy tag -> EtherReader tag r a -> r -> a
46+runEtherReader proxy m r = runIdentity (runEtherReaderT proxy m r)
42mapEtherReaderT :: proxy tag -> (m a -> n b) -> EtherReaderT tag r m a -> EtherReaderT tag r n b
48mapEtherReaderT :: proxy tag -> (m a -> n b) -> EtherReaderT tag r m a -> EtherReaderT tag r n b
43mapEtherReaderT _proxy f m = EtherReaderT $ R.mapReaderT f (coerce m)
49mapEtherReaderT _proxy f m = EtherReaderT $ R.mapReaderT f (coerce m)
@@ -48,6 +54,12 @@ liftCatch _proxy f m h = EtherReaderT $ R.liftCatch f (coerce m) (coerce h)
48liftCallCC :: proxy tag -> Sig.CallCC m a b -> Sig.CallCC (EtherReaderT tag r m) a b
54liftCallCC :: proxy tag -> Sig.CallCC m a b -> Sig.CallCC (EtherReaderT tag r m) a b
49liftCallCC _proxy callCC f = EtherReaderT $ R.liftCallCC callCC (coerce f)
55liftCallCC _proxy callCC f = EtherReaderT $ R.liftCallCC callCC (coerce f)
57+runReaderT' :: EtherReaderT r r m a -> r -> m a
58+runReaderT' = runEtherReaderT Proxy
60+runReader' :: EtherReader r r a -> r -> a
61+runReader' m r = runIdentity (runEtherReaderT Proxy m r)
51-- Instances for mtl classes
63-- Instances for mtl classes
53instance Class.MonadCont m => Class.MonadCont (EtherReaderT tag r m) where
65instance Class.MonadCont m => Class.MonadCont (EtherReaderT tag r m) where