monad-unlift 0.1.2.0 → 0.2.0
raw patch · 6 files changed
+15/−575 lines, 6 filesdep −exceptionsdep −mtldep −mutable-containersPVP ok
version bump matches the API change (PVP)
Dependencies removed: exceptions, mtl, mutable-containers, resourcet, stm
API changes (from Hackage documentation)
- Control.Monad.Trans.RWS.Ref: data RWSRefT refw refs r w s m a
- Control.Monad.Trans.RWS.Ref: instance (Data.Mutable.Class.MCState (refs s) ~ Control.Monad.Primitive.PrimState b, GHC.Base.Monad m, s ~ Data.Mutable.Class.RefElement (refs s), Data.Mutable.Class.MutableRef (refs s), Control.Monad.Primitive.PrimMonad b, Control.Monad.Base.MonadBase b m) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance (Data.Mutable.Class.MCState (refw w) ~ Control.Monad.Primitive.PrimState b, Data.Mutable.Class.MCState (refs s) ~ Control.Monad.Primitive.PrimState b, GHC.Base.Monad m, w ~ Data.Mutable.Class.RefElement (refw w), s ~ Data.Mutable.Class.RefElement (refs s), Data.Mutable.Class.MutableRef (refw w), Data.Mutable.Class.MutableRef (refs s), Control.Monad.Primitive.PrimMonad b, Control.Monad.Base.MonadBase b m, GHC.Base.Monoid w) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance (Data.Mutable.Class.MCState (refw w) ~ Control.Monad.Primitive.PrimState b, GHC.Base.Monad m, w ~ Data.Mutable.Class.RefElement (refw w), Data.Mutable.Class.MutableRef (refw w), Control.Monad.Primitive.PrimMonad b, Control.Monad.Base.MonadBase b m, GHC.Base.Monoid w) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Base.MonadBase b m => Control.Monad.Base.MonadBase b (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Trans.Control.MonadBaseControl b m => Control.Monad.Trans.Control.MonadBaseControl b (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Trans.Control.MonadTransControl (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s)
- Control.Monad.Trans.RWS.Ref: instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance GHC.Base.Applicative m => GHC.Base.Applicative (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Trans.RWS.Ref.RWSRefT refw refs r w s m)
- Control.Monad.Trans.RWS.Ref: runRWSIORefT :: (Monad m, RealWorld ~ PrimState b, MonadBase b m, PrimMonad b, Monoid w) => RWSRefT IORef IORef r w s m a -> r -> s -> m (a, s, w)
- Control.Monad.Trans.RWS.Ref: runRWSRefT :: (Monad m, w ~ RefElement (refw w), s ~ RefElement (refs s), MCState (refw w) ~ PrimState b, MCState (refs s) ~ PrimState b, MonadBase b m, MutableRef (refw w), MutableRef (refs s), PrimMonad b, Monoid w) => RWSRefT refw refs r w s m a -> r -> s -> m (a, s, w)
- Control.Monad.Trans.RWS.Ref: runRWSSTRefT :: (Monad m, ps ~ PrimState b, MonadBase b m, PrimMonad b, Monoid w) => RWSRefT (STRef ps) (STRef ps) r w s m a -> r -> s -> m (a, s, w)
- Control.Monad.Trans.State.Ref: data StateRefT ref s m a
- Control.Monad.Trans.State.Ref: instance (Data.Mutable.Class.MCState (ref s) ~ Control.Monad.Primitive.PrimState b, GHC.Base.Monad m, s ~ Data.Mutable.Class.RefElement (ref s), Data.Mutable.Class.MutableRef (ref s), Control.Monad.Primitive.PrimMonad b, Control.Monad.Base.MonadBase b m) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Base.MonadBase b m => Control.Monad.Base.MonadBase b (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.Trans.State.Ref.StateRefT ref s)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Trans.Control.MonadBaseControl b m => Control.Monad.Trans.Control.MonadBaseControl b (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Trans.Control.MonadTransControl (Control.Monad.Trans.State.Ref.StateRefT ref s)
- Control.Monad.Trans.State.Ref: instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance GHC.Base.Applicative m => GHC.Base.Applicative (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Trans.State.Ref.StateRefT ref s m)
- Control.Monad.Trans.State.Ref: runStateIORefT :: (Monad m, RealWorld ~ PrimState b, MonadBase b m, PrimMonad b) => StateRefT IORef s m a -> s -> m (a, s)
- Control.Monad.Trans.State.Ref: runStateRefT :: (Monad m, s ~ RefElement (ref s), MCState (ref s) ~ PrimState b, MonadBase b m, MutableRef (ref s), PrimMonad b) => StateRefT ref s m a -> s -> m (a, s)
- Control.Monad.Trans.State.Ref: runStateSTRefT :: (Monad m, ps ~ PrimState b, MonadBase b m, PrimMonad b) => StateRefT (STRef ps) s m a -> s -> m (a, s)
- Control.Monad.Trans.Unlift: instance (Control.Monad.Trans.Control.StM m a ~ a) => Control.Monad.Trans.Unlift.IdenticalBase m a
- Control.Monad.Trans.Unlift: instance (Control.Monad.Trans.Control.StT t a ~ a) => Control.Monad.Trans.Unlift.Identical t a
- Control.Monad.Trans.Writer.Ref: data WriterRefT ref w m a
- Control.Monad.Trans.Writer.Ref: instance (Data.Mutable.Class.MCState (ref w) ~ Control.Monad.Primitive.PrimState b, GHC.Base.Monad m, w ~ Data.Mutable.Class.RefElement (ref w), Data.Mutable.Class.MutableRef (ref w), Control.Monad.Primitive.PrimMonad b, Control.Monad.Base.MonadBase b m, GHC.Base.Monoid w) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Base.MonadBase b m => Control.Monad.Base.MonadBase b (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.Trans.Writer.Ref.WriterRefT ref w)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Trans.Control.MonadBaseControl b m => Control.Monad.Trans.Control.MonadBaseControl b (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Trans.Control.MonadTransControl (Control.Monad.Trans.Writer.Ref.WriterRefT ref w)
- Control.Monad.Trans.Writer.Ref: instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance GHC.Base.Applicative m => GHC.Base.Applicative (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Trans.Writer.Ref.WriterRefT ref w m)
- Control.Monad.Trans.Writer.Ref: runWriterIORefT :: (Monad m, RealWorld ~ PrimState b, MonadBase b m, PrimMonad b, Monoid w) => WriterRefT IORef w m a -> m (a, w)
- Control.Monad.Trans.Writer.Ref: runWriterRefT :: (Monad m, w ~ RefElement (ref w), MCState (ref w) ~ PrimState b, MonadBase b m, MutableRef (ref w), PrimMonad b, Monoid w) => WriterRefT ref w m a -> m (a, w)
- Control.Monad.Trans.Writer.Ref: runWriterSTRefT :: (Monad m, ps ~ PrimState b, MonadBase b m, PrimMonad b, Monoid w) => WriterRefT (STRef ps) w m a -> m (a, w)
+ Control.Monad.Trans.Unlift: instance Control.Monad.Trans.Control.StM m a ~ a => Control.Monad.Trans.Unlift.IdenticalBase m a
+ Control.Monad.Trans.Unlift: instance Control.Monad.Trans.Control.StT t a ~ a => Control.Monad.Trans.Unlift.Identical t a
+ Control.Monad.Trans.Unlift: type family StM (m :: * -> *) a :: *;
+ Control.Monad.Trans.Unlift: }
- Control.Monad.Trans.Unlift: askUnlift :: (MonadTransUnlift t, Monad m) => t m (Unlift t)
+ Control.Monad.Trans.Unlift: askUnlift :: forall t m. (MonadTransUnlift t, Monad m) => t m (Unlift t)
- Control.Monad.Trans.Unlift: askUnliftBase :: (MonadBaseUnlift b m) => m (UnliftBase b m)
+ Control.Monad.Trans.Unlift: askUnliftBase :: forall b m. (MonadBaseUnlift b m) => m (UnliftBase b m)
- Control.Monad.Trans.Unlift: class MonadBase b m => MonadBaseControl (b :: * -> *) (m :: * -> *) | m -> b where type family StM (m :: * -> *) a :: *
+ Control.Monad.Trans.Unlift: class MonadBase b m => MonadBaseControl (b :: * -> *) (m :: * -> *) | m -> b where type StM (m :: * -> *) a :: * where {
- Control.Monad.Trans.Unlift: class MonadTrans t => MonadTransControl (t :: (* -> *) -> * -> *) where type family StT (t :: (* -> *) -> * -> *) a :: *
+ Control.Monad.Trans.Unlift: class MonadTrans t => MonadTransControl (t :: (* -> *) -> * -> *) where type StT (t :: (* -> *) -> * -> *) a :: * where {
Files
- ChangeLog.md +4/−0
- Control/Monad/Trans/RWS/Ref.hs +0/−221
- Control/Monad/Trans/State/Ref.hs +0/−162
- Control/Monad/Trans/Writer/Ref.hs +0/−181
- README.md +6/−2
- monad-unlift.cabal +5/−9
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.0++* Split out monad-unlift-ref+ ## 0.1.1.0 * Add `MonadResource` instances
− Control/Monad/Trans/RWS/Ref.hs
@@ -1,221 +0,0 @@-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}--- | An implementation of @RWST@ built on top of mutable references,--- providing a proper monad morphism.------ An additional advantage of this transformer over the standard @RWST@--- transformers in the transformers package is that it does not have space--- leaks in the writer component. For more information, see--- <https://mail.haskell.org/pipermail/libraries/2012-October/018599.html>.------ Please see the documentation at--- <https://www.stackage.org/package/monad-unlift> for more details on using--- this module.-module Control.Monad.Trans.RWS.Ref- ( RWSRefT- , runRWSRefT- , runRWSIORefT- , runRWSSTRefT- , module Control.Monad.RWS.Class- ) where--import Control.Applicative (Applicative (..))-import Control.Monad (ap, liftM)-import Control.Monad.Catch (MonadCatch (..), MonadMask (..),- MonadThrow (..))-import Control.Monad.IO.Class (MonadIO (..))-import Control.Monad.RWS.Class-import Control.Monad.Trans.Control (defaultLiftBaseWith,- defaultRestoreM)-import Control.Monad.Trans.Unlift-import Control.Monad.Trans.Resource (MonadResource (..))-import Data.Monoid (Monoid, mappend, mempty)-import Data.Mutable (IORef, MCState, MutableRef,- PrimMonad, PrimState, RealWorld,- RefElement, STRef, modifyRef',- newRef, readRef, writeRef)---- |------ Since 0.1.0-newtype RWSRefT refw refs r w s m a = RWSRefT- { unRWSRefT :: r -> refw w -> refs s -> m a- }- deriving Functor---- |------ Since 0.1.0-runRWSRefT- :: ( Monad m- , w ~ RefElement (refw w)- , s ~ RefElement (refs s)- , MCState (refw w) ~ PrimState b- , MCState (refs s) ~ PrimState b- , MonadBase b m- , MutableRef (refw w)- , MutableRef (refs s)- , PrimMonad b- , Monoid w- )- => RWSRefT refw refs r w s m a- -> r- -> s- -> m (a, s, w)-runRWSRefT (RWSRefT f) r s0 = do- (refw, refs) <- liftBase $ (,) `liftM` newRef mempty `ap` newRef s0- a <- f r refw refs- (w, s) <- liftBase $ (,) `liftM` readRef refw `ap` readRef refs- return (a, s, w)-{-# INLINEABLE runRWSRefT #-}---- |------ Since 0.1.0-runRWSIORefT- :: ( Monad m- , RealWorld ~ PrimState b- , MonadBase b m- , PrimMonad b- , Monoid w- )- => RWSRefT IORef IORef r w s m a- -> r- -> s- -> m (a, s, w)-runRWSIORefT = runRWSRefT-{-# INLINE runRWSIORefT #-}---- |------ Since 0.1.0-runRWSSTRefT- :: ( Monad m- , ps ~ PrimState b- , MonadBase b m- , PrimMonad b- , Monoid w- )- => RWSRefT (STRef ps) (STRef ps) r w s m a- -> r- -> s- -> m (a, s, w)-runRWSSTRefT = runRWSRefT-{-# INLINE runRWSSTRefT #-}--instance Applicative m => Applicative (RWSRefT refw refs r w s m) where- pure m = RWSRefT $ \_ _ _ -> pure m- {-# INLINE pure #-}- RWSRefT f <*> RWSRefT g = RWSRefT $ \x y z -> f x y z <*> g x y z- {-# INLINE (<*>) #-}-instance Monad m => Monad (RWSRefT refw refs r w s m) where- return m = RWSRefT $ \_ _ _ -> return m- {-# INLINE return #-}- RWSRefT f >>= g = RWSRefT $ \x y z -> do- a <- f x y z- unRWSRefT (g a) x y z- {-# INLINE (>>=) #-}--instance Monad m => MonadReader r (RWSRefT refw refs r w s m) where- ask = RWSRefT $ \r _ _ -> return r- {-# INLINE ask #-}- local f (RWSRefT g) = RWSRefT $ \r w s -> g (f r) w s-instance ( MCState (refw w) ~ PrimState b- , Monad m- , w ~ RefElement (refw w)- , MutableRef (refw w)- , PrimMonad b- , MonadBase b m- , Monoid w- )- => MonadWriter w (RWSRefT refw refs r w s m) where- writer (a, w) = RWSRefT $ \_ ref _ ->- liftBase $ modifyRef' ref (`mappend` w) >> return a- {-# INLINE writer #-}- tell w = RWSRefT $ \_ ref _ -> liftBase $ modifyRef' ref (`mappend` w)- {-# INLINE tell #-}- listen (RWSRefT f) = RWSRefT $ \r _ s -> do- ref <- liftBase (newRef mempty)- a <- f r ref s- w <- liftBase (readRef ref)- return (a, w)- {-# INLINEABLE listen #-}- pass (RWSRefT f) = RWSRefT $ \r ref s -> do- (a, g) <- f r ref s- liftBase $ modifyRef' ref g- return a- {-# INLINEABLE pass #-}-instance ( MCState (refs s) ~ PrimState b- , Monad m- , s ~ RefElement (refs s)- , MutableRef (refs s)- , PrimMonad b- , MonadBase b m- )- => MonadState s (RWSRefT refw refs r w s m) where- get = RWSRefT $ \_ _ -> liftBase . readRef- {-# INLINE get #-}- put x = seq x $ RWSRefT $ \_ _ -> liftBase . (`writeRef` x)- {-# INLINE put #-}-instance ( MCState (refw w) ~ PrimState b- , MCState (refs s) ~ PrimState b- , Monad m- , w ~ RefElement (refw w)- , s ~ RefElement (refs s)- , MutableRef (refw w)- , MutableRef (refs s)- , PrimMonad b- , MonadBase b m- , Monoid w- )- => MonadRWS r w s (RWSRefT refw refs r w s m)--instance MonadTrans (RWSRefT refw refs r w s) where- lift f = RWSRefT $ \_ _ _ -> f- {-# INLINE lift #-}-instance MonadIO m => MonadIO (RWSRefT refw refs r w s m) where- liftIO = lift . liftIO- {-# INLINE liftIO #-}-instance MonadBase b m => MonadBase b (RWSRefT refw refs r w s m) where- liftBase = lift . liftBase- {-# INLINE liftBase #-}--instance MonadTransControl (RWSRefT refw refs r w s) where- type StT (RWSRefT refw refs r w s) a = a- liftWith f = RWSRefT $ \r w s -> f $ \t -> unRWSRefT t r w s- restoreT f = RWSRefT $ \_ _ _ -> f- {-# INLINABLE liftWith #-}- {-# INLINABLE restoreT #-}--instance MonadBaseControl b m => MonadBaseControl b (RWSRefT refw refs r w s m) where- type StM (RWSRefT refw refs r w s m) a = StM m a- liftBaseWith = defaultLiftBaseWith- restoreM = defaultRestoreM- {-# INLINE liftBaseWith #-}- {-# INLINE restoreM #-}--instance MonadThrow m => MonadThrow (RWSRefT refw refs r w s m) where- throwM = lift . throwM- {-# INLINE throwM #-}-instance MonadCatch m => MonadCatch (RWSRefT refw refs r w s m) where- catch (RWSRefT f) g = RWSRefT $ \e w s -> catch (f e w s)- ((\m -> unRWSRefT m e w s) . g)--instance MonadMask m => MonadMask (RWSRefT refw refs r w s m) where- mask a = RWSRefT $ \e w s -> mask $ \u -> unRWSRefT (a $ q u) e w s- where q :: (m a -> m a) -> RWSRefT refw refs r w s m a -> RWSRefT refw refs r w s m a- q u (RWSRefT b) = RWSRefT (\r w s -> u (b r w s))- {-# INLINE mask #-}- uninterruptibleMask a =- RWSRefT $ \e w s -> uninterruptibleMask $ \u -> unRWSRefT (a $ q u) e w s- where q :: (m a -> m a) -> RWSRefT refw refs r w s m a -> RWSRefT refw refs r w s m a- q u (RWSRefT b) = RWSRefT (\r w s -> u (b r w s))- {-# INLINE uninterruptibleMask #-}--instance MonadResource m => MonadResource (RWSRefT refw refs r w s m) where- liftResourceT = lift . liftResourceT- {-# INLINE liftResourceT #-}
− Control/Monad/Trans/State/Ref.hs
@@ -1,162 +0,0 @@-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}--- | An implementation of @StateT@ built on top of mutable references,--- providing a proper monad morphism.------ Please see the documentation at--- <https://www.stackage.org/package/monad-unlift> for more details on using--- this module.-module Control.Monad.Trans.State.Ref- ( StateRefT- , runStateRefT- , runStateIORefT- , runStateSTRefT- , module Control.Monad.State.Class- ) where--import Control.Applicative (Applicative (..))-import Control.Monad.Catch (MonadCatch (..), MonadMask (..),- MonadThrow (..))-import Control.Monad.IO.Class (MonadIO (..))-import Control.Monad.State.Class-import Control.Monad.Trans.Control (defaultLiftBaseWith,- defaultRestoreM)-import Control.Monad.Trans.Unlift-import Control.Monad.Trans.Resource (MonadResource (..))-import Data.Mutable (IORef, MCState, MutableRef,- PrimMonad, PrimState, RealWorld,- RefElement, STRef, newRef,- readRef, writeRef)---- |------ Since 0.1.0-newtype StateRefT ref s m a = StateRefT- { unStateRefT :: ref s -> m a- }- deriving Functor---- |------ Since 0.1.0-runStateRefT- :: ( Monad m- , s ~ RefElement (ref s)- , MCState (ref s) ~ PrimState b- , MonadBase b m- , MutableRef (ref s)- , PrimMonad b- )- => StateRefT ref s m a- -> s- -> m (a, s)-runStateRefT (StateRefT f) v0 = do- ref <- liftBase $ newRef v0- a <- f ref- v <- liftBase $ readRef ref- return (a, v)-{-# INLINEABLE runStateRefT #-}---- |------ Since 0.1.0-runStateIORefT- :: ( Monad m- , RealWorld ~ PrimState b- , MonadBase b m- , PrimMonad b- )- => StateRefT IORef s m a- -> s- -> m (a, s)-runStateIORefT = runStateRefT-{-# INLINE runStateIORefT #-}---- |------ Since 0.1.0-runStateSTRefT- :: ( Monad m- , ps ~ PrimState b- , MonadBase b m- , PrimMonad b- )- => StateRefT (STRef ps) s m a- -> s- -> m (a, s)-runStateSTRefT = runStateRefT-{-# INLINE runStateSTRefT #-}--instance Applicative m => Applicative (StateRefT ref s m) where- pure = StateRefT . const . pure- {-# INLINE pure #-}- StateRefT f <*> StateRefT g = StateRefT $ \x -> f x <*> g x- {-# INLINE (<*>) #-}-instance Monad m => Monad (StateRefT ref s m) where- return = StateRefT . const . return- {-# INLINE return #-}- StateRefT f >>= g = StateRefT $ \x -> do- a <- f x- unStateRefT (g a) x- {-# INLINE (>>=) #-}-instance ( MCState (ref s) ~ PrimState b- , Monad m- , s ~ RefElement (ref s)- , MutableRef (ref s)- , PrimMonad b- , MonadBase b m- )- => MonadState s (StateRefT ref s m) where- get = StateRefT $ liftBase . readRef- {-# INLINE get #-}- put x = seq x $ StateRefT $ liftBase . (`writeRef` x)- {-# INLINE put #-}--instance MonadTrans (StateRefT ref s) where- lift = StateRefT . const- {-# INLINE lift #-}-instance MonadIO m => MonadIO (StateRefT ref s m) where- liftIO = lift . liftIO- {-# INLINE liftIO #-}-instance MonadBase b m => MonadBase b (StateRefT ref s m) where- liftBase = lift . liftBase- {-# INLINE liftBase #-}--instance MonadTransControl (StateRefT ref s) where- type StT (StateRefT ref s) a = a- liftWith f = StateRefT $ \r -> f $ \t -> unStateRefT t r- restoreT = StateRefT . const- {-# INLINABLE liftWith #-}- {-# INLINABLE restoreT #-}--instance MonadBaseControl b m => MonadBaseControl b (StateRefT ref s m) where- type StM (StateRefT ref s m) a = StM m a- liftBaseWith = defaultLiftBaseWith- restoreM = defaultRestoreM- {-# INLINE liftBaseWith #-}- {-# INLINE restoreM #-}--instance MonadThrow m => MonadThrow (StateRefT ref s m) where- throwM = lift . throwM- {-# INLINE throwM #-}-instance MonadCatch m => MonadCatch (StateRefT ref s m) where- catch (StateRefT f) g = StateRefT $ \e -> catch (f e) ((`unStateRefT` e) . g)--instance MonadMask m => MonadMask (StateRefT ref s m) where- mask a = StateRefT $ \e -> mask $ \u -> unStateRefT (a $ q u) e- where q :: (m a -> m a) -> StateRefT ref s m a -> StateRefT ref s m a- q u (StateRefT b) = StateRefT (u . b)- {-# INLINE mask #-}- uninterruptibleMask a =- StateRefT $ \e -> uninterruptibleMask $ \u -> unStateRefT (a $ q u) e- where q :: (m a -> m a) -> StateRefT ref s m a -> StateRefT ref s m a- q u (StateRefT b) = StateRefT (u . b)- {-# INLINE uninterruptibleMask #-}--instance MonadResource m => MonadResource (StateRefT ref s m) where- liftResourceT = lift . liftResourceT- {-# INLINE liftResourceT #-}
− Control/Monad/Trans/Writer/Ref.hs
@@ -1,181 +0,0 @@-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}--- | An implementation of @WriterT@ built on top of mutable references,--- providing a proper monad morphism.------ An additional advantage of this transformer over the standard @WriterT@--- transformers in the transformers package is that it does not have space--- leaks. For more information, see--- <https://mail.haskell.org/pipermail/libraries/2012-October/018599.html>.------ Please see the documentation at--- <https://www.stackage.org/package/monad-unlift> for more details on using--- this module.-module Control.Monad.Trans.Writer.Ref- ( WriterRefT- , runWriterRefT- , runWriterIORefT- , runWriterSTRefT- , module Control.Monad.Writer.Class- ) where--import Control.Applicative (Applicative (..))-import Control.Monad.Catch (MonadCatch (..), MonadMask (..),- MonadThrow (..))-import Control.Monad.IO.Class (MonadIO (..))-import Control.Monad.Trans.Control (defaultLiftBaseWith,- defaultRestoreM)-import Control.Monad.Trans.Unlift-import Control.Monad.Trans.Resource (MonadResource (..))-import Control.Monad.Writer.Class-import Data.Monoid (Monoid, mappend, mempty)-import Data.Mutable (IORef, MCState, MutableRef,- PrimMonad, PrimState, RealWorld,- RefElement, STRef, modifyRef',- newRef, readRef, writeRef)---- |------ Since 0.1.0-newtype WriterRefT ref w m a = WriterRefT- { unWriterRefT :: ref w -> m a- }- deriving Functor---- |------ Since 0.1.0-runWriterRefT- :: ( Monad m- , w ~ RefElement (ref w)- , MCState (ref w) ~ PrimState b- , MonadBase b m- , MutableRef (ref w)- , PrimMonad b- , Monoid w- )- => WriterRefT ref w m a- -> m (a, w)-runWriterRefT (WriterRefT f) = do- ref <- liftBase $ newRef mempty- a <- f ref- v <- liftBase $ readRef ref- return (a, v)-{-# INLINEABLE runWriterRefT #-}---- |------ Since 0.1.0-runWriterIORefT- :: ( Monad m- , RealWorld ~ PrimState b- , MonadBase b m- , PrimMonad b- , Monoid w- )- => WriterRefT IORef w m a- -> m (a, w)-runWriterIORefT = runWriterRefT-{-# INLINE runWriterIORefT #-}---- |------ Since 0.1.0-runWriterSTRefT- :: ( Monad m- , ps ~ PrimState b- , MonadBase b m- , PrimMonad b- , Monoid w- )- => WriterRefT (STRef ps) w m a- -> m (a, w)-runWriterSTRefT = runWriterRefT-{-# INLINE runWriterSTRefT #-}--instance Applicative m => Applicative (WriterRefT ref w m) where- pure = WriterRefT . const . pure- {-# INLINE pure #-}- WriterRefT f <*> WriterRefT g = WriterRefT $ \x -> f x <*> g x- {-# INLINE (<*>) #-}-instance Monad m => Monad (WriterRefT ref w m) where- return = WriterRefT . const . return- {-# INLINE return #-}- WriterRefT f >>= g = WriterRefT $ \x -> do- a <- f x- unWriterRefT (g a) x- {-# INLINE (>>=) #-}-instance ( MCState (ref w) ~ PrimState b- , Monad m- , w ~ RefElement (ref w)- , MutableRef (ref w)- , PrimMonad b- , MonadBase b m- , Monoid w- )- => MonadWriter w (WriterRefT ref w m) where- writer (a, w) = WriterRefT $ \ref ->- liftBase $ modifyRef' ref (`mappend` w) >> return a- {-# INLINE writer #-}- tell w = WriterRefT $ \ref -> liftBase $ modifyRef' ref (`mappend` w)- {-# INLINE tell #-}- listen (WriterRefT f) = lift $ do- ref <- liftBase (newRef mempty)- a <- f ref- w <- liftBase (readRef ref)- return (a, w)- {-# INLINEABLE listen #-}- pass (WriterRefT f) = WriterRefT $ \ref -> do- (a, g) <- f ref- liftBase $ modifyRef' ref g- return a- {-# INLINEABLE pass #-}--instance MonadTrans (WriterRefT ref w) where- lift = WriterRefT . const- {-# INLINE lift #-}-instance MonadIO m => MonadIO (WriterRefT ref w m) where- liftIO = lift . liftIO- {-# INLINE liftIO #-}-instance MonadBase b m => MonadBase b (WriterRefT ref w m) where- liftBase = lift . liftBase- {-# INLINE liftBase #-}--instance MonadTransControl (WriterRefT ref w) where- type StT (WriterRefT ref w) a = a- liftWith f = WriterRefT $ \r -> f $ \t -> unWriterRefT t r- restoreT = WriterRefT . const- {-# INLINABLE liftWith #-}- {-# INLINABLE restoreT #-}--instance MonadBaseControl b m => MonadBaseControl b (WriterRefT ref w m) where- type StM (WriterRefT ref w m) a = StM m a- liftBaseWith = defaultLiftBaseWith- restoreM = defaultRestoreM- {-# INLINE liftBaseWith #-}- {-# INLINE restoreM #-}--instance MonadThrow m => MonadThrow (WriterRefT ref w m) where- throwM = lift . throwM- {-# INLINE throwM #-}-instance MonadCatch m => MonadCatch (WriterRefT ref w m) where- catch (WriterRefT f) g = WriterRefT $ \e -> catch (f e) ((`unWriterRefT` e) . g)--instance MonadMask m => MonadMask (WriterRefT ref w m) where- mask a = WriterRefT $ \e -> mask $ \u -> unWriterRefT (a $ q u) e- where q :: (m a -> m a) -> WriterRefT ref w m a -> WriterRefT ref w m a- q u (WriterRefT b) = WriterRefT (u . b)- {-# INLINE mask #-}- uninterruptibleMask a =- WriterRefT $ \e -> uninterruptibleMask $ \u -> unWriterRefT (a $ q u) e- where q :: (m a -> m a) -> WriterRefT ref w m a -> WriterRefT ref w m a- q u (WriterRefT b) = WriterRefT (u . b)- {-# INLINE uninterruptibleMask #-}--instance MonadResource m => MonadResource (WriterRefT ref w m) where- liftResourceT = lift . liftResourceT- {-# INLINE liftResourceT #-}
README.md view
@@ -1,7 +1,11 @@ ## monad-unlift -Typeclasses for providing for unlifting of monad transformers and stacks, and-concrete implementations of common transformers implementing this type classes.+[](https://travis-ci.org/fpco/monad-unlift)++Typeclasses for providing for unlifting of monad transformers and stacks.++Note that concrete implementations of common transformers implementing+these type classes are provided by the monad-unlift-ref package. ## Synopsis
monad-unlift.cabal view
@@ -1,5 +1,5 @@ name: monad-unlift-version: 0.1.2.0+version: 0.2.0 synopsis: Typeclasses for representing monad transformer unlifting description: See README.md homepage: https://github.com/fpco/monad-unlift@@ -15,17 +15,13 @@ library exposed-modules: Control.Monad.Trans.Unlift- Control.Monad.Trans.State.Ref- Control.Monad.Trans.Writer.Ref- Control.Monad.Trans.RWS.Ref build-depends: base >= 4.6 && < 5 , monad-control >= 1.0 && < 1.1 , transformers- , mtl , transformers-base- , mutable-containers >= 0.3 && < 0.4- , exceptions >= 0.6- , stm , constraints- , resourcet default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/fpco/monad-unlift.git