Skip to content

Add MonadAff instances for transformers #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/Control.Monad.Aff.Class.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class MonadAff e m where
##### Instances
``` purescript
instance monadAffAff :: MonadAff e (Aff e)
instance monadAffContT :: (Monad m, MonadAff eff m) => MonadAff eff (ContT r m)
instance monadAffError :: (Monad m, MonadAff eff m) => MonadAff eff (ErrorT e m)
instance monadAffExceptT :: (Monad m, MonadAff eff m) => MonadAff eff (ExceptT e m)
instance monadAffListT :: (Monad m, MonadAff eff m) => MonadAff eff (ListT m)
instance monadAffMaybe :: (Monad m, MonadAff eff m) => MonadAff eff (MaybeT m)
instance monadAffReader :: (Monad m, MonadAff eff m) => MonadAff eff (ReaderT r m)
instance monadAffRWS :: (Monad m, Monoid w, MonadAff eff m) => MonadAff eff (RWST r w s m)
instance monadAffState :: (Monad m, MonadAff eff m) => MonadAff eff (StateT s m)
instance monadAffWriter :: (Monad m, Monoid w, MonadAff eff m) => MonadAff eff (WriterT w m)
```


43 changes: 42 additions & 1 deletion src/Control/Monad/Aff/Class.purs
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
module Control.Monad.Aff.Class where
import Prelude (id)

import Prelude

import Control.Monad.Aff
import Control.Monad.Cont.Trans (ContT())
import Control.Monad.Error.Trans (ErrorT())
import Control.Monad.Except.Trans (ExceptT())
import Control.Monad.List.Trans (ListT())
import Control.Monad.Maybe.Trans (MaybeT())
import Control.Monad.Reader.Trans (ReaderT())
import Control.Monad.RWS.Trans (RWST())
import Control.Monad.State.Trans (StateT())
import Control.Monad.Trans (lift)
import Control.Monad.Writer.Trans (WriterT())

import Data.Monoid (Monoid)

class MonadAff e m where
liftAff :: forall a. Aff e a -> m a

instance monadAffAff :: MonadAff e (Aff e) where
liftAff = id

instance monadAffContT :: (Monad m, MonadAff eff m) => MonadAff eff (ContT r m) where
liftAff = lift <<< liftAff

instance monadAffError :: (Monad m, MonadAff eff m) => MonadAff eff (ErrorT e m) where
liftAff = lift <<< liftAff

instance monadAffExceptT :: (Monad m, MonadAff eff m) => MonadAff eff (ExceptT e m) where
liftAff = lift <<< liftAff

instance monadAffListT :: (Monad m, MonadAff eff m) => MonadAff eff (ListT m) where
liftAff = lift <<< liftAff

instance monadAffMaybe :: (Monad m, MonadAff eff m) => MonadAff eff (MaybeT m) where
liftAff = lift <<< liftAff

instance monadAffReader :: (Monad m, MonadAff eff m) => MonadAff eff (ReaderT r m) where
liftAff = lift <<< liftAff

instance monadAffRWS :: (Monad m, Monoid w, MonadAff eff m) => MonadAff eff (RWST r w s m) where
liftAff = lift <<< liftAff

instance monadAffState :: (Monad m, MonadAff eff m) => MonadAff eff (StateT s m) where
liftAff = lift <<< liftAff

instance monadAffWriter :: (Monad m, Monoid w, MonadAff eff m) => MonadAff eff (WriterT w m) where
liftAff = lift <<< liftAff