diff --git a/CHANGELOG.md b/CHANGELOG.md index caba2d81..12e7418e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Add `MonadST` instances for all monad transformers (#147 by @rhendric) - Add `ComonadAsk`, `ComonadEnv`, and `ComonadTraced` instances for `StoreT`, `EnvT`, and `TracedT` (#145 by @skeate) Bugfixes: diff --git a/bower.json b/bower.json index ae65e0cd..89b87e20 100644 --- a/bower.json +++ b/bower.json @@ -34,6 +34,7 @@ "purescript-maybe": "^6.0.0", "purescript-newtype": "^5.0.0", "purescript-prelude": "^6.0.0", + "purescript-st": "^6.2.0", "purescript-tailrec": "^6.0.0", "purescript-tuples": "^7.0.0", "purescript-unfoldable": "^6.0.0" diff --git a/src/Control/Monad/Cont/Trans.purs b/src/Control/Monad/Cont/Trans.purs index dfb0f405..7cc92066 100644 --- a/src/Control/Monad/Cont/Trans.purs +++ b/src/Control/Monad/Cont/Trans.purs @@ -11,6 +11,7 @@ import Prelude import Control.Apply (lift2) import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Data.Newtype (class Newtype) @@ -75,3 +76,6 @@ instance semigroupContT :: (Apply m, Semigroup a) => Semigroup (ContT r m a) whe instance monoidContT :: (Applicative m, Monoid a) => Monoid (ContT r m a) where mempty = pure mempty + +instance MonadST s m => MonadST s (ContT r m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/Except/Trans.purs b/src/Control/Monad/Except/Trans.purs index 3e25a8af..1901d677 100644 --- a/src/Control/Monad/Except/Trans.purs +++ b/src/Control/Monad/Except/Trans.purs @@ -15,6 +15,7 @@ import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Error.Class (class MonadThrow, class MonadError, throwError, catchError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local) import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..)) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadWriter, class MonadTell, pass, listen, tell) @@ -141,3 +142,5 @@ instance semigroupExceptT :: (Monad m, Semigroup a) => Semigroup (ExceptT e m a) instance monoidExceptT :: (Monad m, Monoid a) => Monoid (ExceptT e m a) where mempty = pure mempty +instance MonadST s m => MonadST s (ExceptT e m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/Identity/Trans.purs b/src/Control/Monad/Identity/Trans.purs index e7ba6f07..aa596c69 100644 --- a/src/Control/Monad/Identity/Trans.purs +++ b/src/Control/Monad/Identity/Trans.purs @@ -9,6 +9,7 @@ import Control.Monad.Cont.Class (class MonadCont) import Control.Monad.Error.Class (class MonadError, class MonadThrow) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader) import Control.Monad.Rec.Class (class MonadRec) +import Control.Monad.ST.Class (class MonadST) import Control.Monad.State.Class (class MonadState) import Control.Monad.Trans.Class (class MonadTrans) import Control.Monad.Writer.Class (class MonadTell, class MonadWriter) @@ -69,6 +70,8 @@ derive newtype instance monadWriterIdentityT :: MonadWriter w m => MonadWriter w derive newtype instance foldableIdentityT :: Foldable m => Foldable (IdentityT m) derive newtype instance traversableIdentityT :: Traversable m => Traversable (IdentityT m) +derive newtype instance MonadST s m => MonadST s (IdentityT m) + instance extendIdentityI :: Extend w => Extend (IdentityT w) where extend f (IdentityT m) = IdentityT (extend (f <<< IdentityT) m) diff --git a/src/Control/Monad/List/Trans.purs b/src/Control/Monad/List/Trans.purs index 41b1e863..aacb08f7 100644 --- a/src/Control/Monad/List/Trans.purs +++ b/src/Control/Monad/List/Trans.purs @@ -41,6 +41,7 @@ import Prelude import Control.Alt (class Alt) import Control.Alternative (class Alternative) import Control.Monad.Rec.Class as MR +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.MonadPlus (class MonadPlus) import Control.Plus (class Plus) @@ -325,3 +326,6 @@ instance monadPlusListT :: Monad f => MonadPlus (ListT f) instance monadEffectListT :: MonadEffect m => MonadEffect (ListT m) where liftEffect = lift <<< liftEffect + +instance MonadST s m => MonadST s (ListT m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/Maybe/Trans.purs b/src/Control/Monad/Maybe/Trans.purs index ac0c97ac..db43fbc8 100644 --- a/src/Control/Monad/Maybe/Trans.purs +++ b/src/Control/Monad/Maybe/Trans.purs @@ -14,6 +14,7 @@ import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local) import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..)) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadWriter, class MonadTell, pass, listen, tell) @@ -126,3 +127,5 @@ instance semigroupMaybeT :: (Monad m, Semigroup a) => Semigroup (MaybeT m a) whe instance monoidMaybeT :: (Monad m, Monoid a) => Monoid (MaybeT m a) where mempty = pure mempty +instance MonadST s m => MonadST s (MaybeT m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/RWS/Trans.purs b/src/Control/Monad/RWS/Trans.purs index 269c1c26..30610a27 100644 --- a/src/Control/Monad/RWS/Trans.purs +++ b/src/Control/Monad/RWS/Trans.purs @@ -15,6 +15,7 @@ import Control.Lazy (class Lazy) import Control.Monad.Error.Class (class MonadThrow, class MonadError, throwError, catchError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader) import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..)) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadWriter, class MonadTell) @@ -138,3 +139,5 @@ instance semigroupRWST :: (Bind m, Monoid w, Semigroup a) => Semigroup (RWST r w instance monoidRWST :: (Monad m, Monoid w, Monoid a) => Monoid (RWST r w s m a) where mempty = pure mempty +instance (Monoid w, MonadST s m) => MonadST s (RWST r w s' m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/Reader/Trans.purs b/src/Control/Monad/Reader/Trans.purs index 6ad6e635..9c4a33c3 100644 --- a/src/Control/Monad/Reader/Trans.purs +++ b/src/Control/Monad/Reader/Trans.purs @@ -15,6 +15,7 @@ import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, asks, local) import Control.Monad.Rec.Class (class MonadRec, tailRecM) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadWriter, class MonadTell, pass, listen, tell) @@ -119,3 +120,6 @@ instance monadRecReaderT :: MonadRec m => MonadRec (ReaderT r m) where tailRecM k a = ReaderT \r -> tailRecM (k' r) a where k' r a' = case k a' of ReaderT f -> pure =<< f r + +instance MonadST s m => MonadST s (ReaderT r m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/State/Trans.purs b/src/Control/Monad/State/Trans.purs index e6daf3fb..bb56c72d 100644 --- a/src/Control/Monad/State/Trans.purs +++ b/src/Control/Monad/State/Trans.purs @@ -16,6 +16,7 @@ import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local) import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..)) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, get, gets, modify, modify_, put, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadWriter, class MonadTell, pass, listen, tell) @@ -142,3 +143,5 @@ instance semigroupStateT :: (Monad m, Semigroup a) => Semigroup (StateT s m a) w instance monoidStateT :: (Monad m, Monoid a) => Monoid (StateT s m a) where mempty = pure mempty +instance MonadST s m => MonadST s (StateT s' m) where + liftST = lift <<< liftST diff --git a/src/Control/Monad/Writer/Trans.purs b/src/Control/Monad/Writer/Trans.purs index b5e5fa54..f915c0ac 100644 --- a/src/Control/Monad/Writer/Trans.purs +++ b/src/Control/Monad/Writer/Trans.purs @@ -15,6 +15,7 @@ import Control.Monad.Cont.Class (class MonadCont, callCC) import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError) import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local) import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..)) +import Control.Monad.ST.Class (class MonadST, liftST) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Monad.Writer.Class (class MonadTell, tell, class MonadWriter, censor, listen, listens, pass) @@ -130,3 +131,5 @@ instance semigroupWriterT :: (Apply m, Semigroup w, Semigroup a) => Semigroup (W instance monoidWriterT :: (Applicative m, Monoid w, Monoid a) => Monoid (WriterT w m a) where mempty = pure mempty +instance (Monoid w, MonadST s m) => MonadST s (WriterT w m) where + liftST = lift <<< liftST