Commit c8af65eb authored by chessai's avatar chessai Committed by GitHub

add (existing mtl typeclass) instances for AccumT (#80)

parent 1a7d01fb
......@@ -6,6 +6,7 @@ Unreleased
`Control.Monad.Error.Class`, and re-export from `Control.Monad.Except`.
* Remove `Control.Monad.List` and `Control.Monad.Error`
* Remove instances of deprecated `ListT` and `ErrorT`
* Add instances for `Control.Monad.Trans.Accum`
2.2.2
-----
......
......@@ -66,6 +66,10 @@ import Control.Monad.Trans.State.Strict as StrictState
import Control.Monad.Trans.Writer.Lazy as LazyWriter
import Control.Monad.Trans.Writer.Strict as StrictWriter
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum as Accum
#endif
#if MIN_VERSION_transformers(0,5,6)
import Control.Monad.Trans.RWS.CPS as CPSRWS
import Control.Monad.Trans.Writer.CPS as CPSWriter
......@@ -144,3 +148,15 @@ instance (Monoid w, MonadCont m) => MonadCont (CPSRWS.RWST r w s m) where
instance (Monoid w, MonadCont m) => MonadCont (CPSWriter.WriterT w m) where
callCC = CPSWriter.liftCallCC callCC
#endif
#if MIN_VERSION_transformers(0,5,3)
-- | @since 2.3
instance
( Monoid w
, MonadCont m
#if !MIN_VERSION_base(4,8,0)
, Functor m
#endif
) => MonadCont (AccumT w m) where
callCC = Accum.liftCallCC callCC
#endif
......@@ -60,6 +60,10 @@ import Control.Monad.Trans.State.Strict as StrictState
import Control.Monad.Trans.Writer.Lazy as LazyWriter
import Control.Monad.Trans.Writer.Strict as StrictWriter
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum as Accum
#endif
#if MIN_VERSION_transformers(0,5,6)
import Control.Monad.Trans.RWS.CPS as CPSRWS
import Control.Monad.Trans.Writer.CPS as CPSWriter
......@@ -201,6 +205,19 @@ instance (Monoid w, MonadError e m) => MonadError e (CPSWriter.WriterT w m) wher
catchError = CPSWriter.liftCatch catchError
#endif
#if MIN_VERSION_transformers(0,5,3)
-- | @since 2.3
instance
( Monoid w
, MonadError e m
#if !MIN_VERSION_base(4,8,0)
, Functor m
#endif
) => MonadError e (AccumT w m) where
throwError = lift . throwError
catchError = Accum.liftCatch catchError
#endif
-- | 'MonadError' analogue to the 'Control.Exception.try' function.
tryError :: MonadError e m => m a -> m (Either e a)
tryError action = (liftM Right action) `catchError` (return . Left)
......
......@@ -59,6 +59,10 @@ import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum as Accum
#endif
#if MIN_VERSION_transformers(0,5,6)
import qualified Control.Monad.Trans.RWS.CPS as CPSRWS (RWST, ask, local, reader)
import Control.Monad.Trans.Writer.CPS as CPS
......@@ -186,3 +190,17 @@ instance (Monoid w, MonadReader r m) => MonadReader r (Strict.WriterT w m) where
ask = lift ask
local = Strict.mapWriterT . local
reader = lift . reader
#if MIN_VERSION_transformers(0,5,3)
-- | @since 2.3
instance
( Monoid w
, MonadReader r m
#if !MIN_VERSION_base(4,8,0)
, Functor m
#endif
) => MonadReader r (AccumT w m) where
ask = lift ask
local = Accum.mapAccumT . local
reader = lift . reader
#endif
......@@ -44,6 +44,10 @@ import qualified Control.Monad.Trans.State.Strict as Strict (StateT, get, put, s
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum as Accum
#endif
#if MIN_VERSION_transformers(0,5,6)
import qualified Control.Monad.Trans.RWS.CPS as CPSRWS (RWST, get, put, state)
import Control.Monad.Trans.Writer.CPS as CPS
......@@ -183,3 +187,18 @@ instance (Monoid w, MonadState s m) => MonadState s (Strict.WriterT w m) where
get = lift get
put = lift . put
state = lift . state
#if MIN_VERSION_transformers(0,5,3)
-- | @since 2.3
instance
( Monoid w
, MonadState s m
#if !MIN_VERSION_base(4,8,0)
, Functor m
#endif
) => MonadState s (AccumT w m) where
get = lift get
put = lift . put
state = lift . state
#endif
......@@ -45,6 +45,10 @@ import qualified Control.Monad.Trans.Writer.Lazy as Lazy (
import qualified Control.Monad.Trans.Writer.Strict as Strict (
WriterT, writer, tell, listen, pass)
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum as Accum
#endif
#if MIN_VERSION_transformers(0,5,6)
import qualified Control.Monad.Trans.RWS.CPS as CPSRWS (
RWST, writer, tell, listen, pass)
......@@ -204,3 +208,26 @@ instance MonadWriter w m => MonadWriter w (Strict.StateT s m) where
tell = lift . tell
listen = Strict.liftListen listen
pass = Strict.liftPass pass
#if MIN_VERSION_transformers(0,5,3)
-- | There are two valid instances for 'AccumT'. It could either:
--
-- 1. Lift the operations to the inner @MonadWriter@
-- 2. Handle the operations itself, à la a @WriterT@.
--
-- This instance chooses (1), reflecting that the intent
-- of 'AccumT' as a type is different than that of @WriterT@.
--
-- @since 2.3
instance
( Monoid w
, MonadWriter w m
#if !MIN_VERSION_base(4,8,0)
, Functor m
#endif
) => MonadWriter w (AccumT w m) where
writer = lift . writer
tell = lift . tell
listen = Accum.liftListen listen
pass = Accum.liftPass pass
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment