interruptible 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+75/−7 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Trans.Interruptible: inEitherTCtx :: a -> RSt (EitherT e) a
+ Control.Monad.Trans.Interruptible: inRWSTCtx :: Monoid w => r -> s -> a -> RSt (RWST r w s) a
+ Control.Monad.Trans.Interruptible: inReaderTCtx :: r -> a -> RSt (ReaderT r) a
+ Control.Monad.Trans.Interruptible: inStateTCtx :: st -> a -> RSt (StateT st) a
+ Control.Monad.Trans.Interruptible: inWriterTCtx :: Monoid w => a -> RSt (WriterT w) a
+ Control.Monad.Trans.Interruptible: peelEitherTCtx :: RSt (EitherT e) a -> Either e a
+ Control.Monad.Trans.Interruptible: peelRWSTCtx :: RSt (RWST r w s) a -> (a, w, s)
+ Control.Monad.Trans.Interruptible: peelReaderTCtx :: RSt (ReaderT r) a -> a
+ Control.Monad.Trans.Interruptible: peelStateTCtx :: RSt (StateT st) a -> (a, st)
+ Control.Monad.Trans.Interruptible: peelWriterTCtx :: RSt (WriterT w) a -> (a, w)
Files
interruptible.cabal view
@@ -2,17 +2,17 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: interruptible-version: 0.1.0.0+version: 0.1.1.0 synopsis: Monad transformers that can be run and resumed later, conserving their context. description: Given an inner monad and a transformer: > (Monad m, MonadTrans t)- If @t@ is an interruptible transformer, it becomes possible to intercalate executions- on the @t@ context with executions over the inner monad @m@ by breaking the execution- on @t@ and resuming it later.+ If t is an interruptible transformer, it becomes possible to intercalate executions+ on the t context with executions over the inner monad m by breaking the execution+ on t and resuming it later. .- Interruptible monads implement the @runI@ function so that, given @f :: a -> t m b@ and- @g :: b -> t m c@, @resume (f >>= g)@ is equivalent to @\x -> resume f x >>= resume g@.+ Interruptible monads implement the @runI@ function so that, given 'f :: a -> t m b' and+ 'g :: b -> t m c', 'resume (f >>= g)' is equivalent to '\x -> resume f x >>= resume g'. . That makes it possible to intercalate the execution of different monads, and even to return a monadic context for another function to resume it.@@ -35,7 +35,7 @@ source-repository this type: git location: https://sealgram.com/git/haskell/interruptible/- tag: 0.1.0.0+ tag: 0.1.1.0 library
src/Control/Monad/Trans/Interruptible/Class.hs view
@@ -2,6 +2,12 @@ module Control.Monad.Trans.Interruptible.Class ( Interruptible(..),+ -- * Instance accessors+ inEitherTCtx, peelEitherTCtx,+ inStateTCtx, peelStateTCtx,+ inWriterTCtx, peelWriterTCtx,+ inReaderTCtx, peelReaderTCtx,+ inRWSTCtx, peelRWSTCtx, -- * Resumers for stacks of interruptibles resume2, resume3,@@ -12,6 +18,9 @@ import Control.Monad.Trans.Class import Control.Monad.Trans.State import Control.Monad.Trans.Either+import Control.Monad.Trans.Reader+import Control.Monad.Trans.Writer+import Control.Monad.Trans.RWS {- | Interruptible monad transformers.@@ -51,10 +60,69 @@ type RSt (EitherT e) a = Either e a resume f st = runEitherT (hoistEither st >>= f) +-- | Cretes an interrupted EitherT context+inEitherTCtx :: a -> RSt (EitherT e) a+inEitherTCtx = Right++-- | Unwraps an interrupted EitherT context+peelEitherTCtx :: RSt (EitherT e) a -> Either e a+peelEitherTCtx = id+ instance Interruptible (StateT st) where -- | The context of @StateT st a@ is @(a, st)@ type RSt (StateT st) a = (a, st) resume f (a, st) = runStateT (f a) st++-- | Creates an interrupted StateT context+inStateTCtx :: st -> a -> RSt (StateT st) a+inStateTCtx st a = (a, st)++-- | Unwraps an interrupted StateT context+peelStateTCtx :: RSt (StateT st) a -> (a, st)+peelStateTCtx = id+++instance Monoid w => Interruptible (WriterT w) where+ type RSt (WriterT w) a = (a, w)+ resume f (a, w) = do+ (a', w') <- runWriterT (f a)+ return (a', mappend w w')++-- | Creates an interrupted WriterT context+inWriterTCtx :: Monoid w => a -> RSt (WriterT w) a+inWriterTCtx a = (a, mempty)++-- | Unwraps an interrupted WriterT context+peelWriterTCtx :: RSt (WriterT w) a -> (a, w)+peelWriterTCtx = id++instance Interruptible (ReaderT r) where+ type RSt (ReaderT r) a = (a, r)+ resume f (a, r) = do+ a' <- runReaderT (f a) r+ return (a', r)+ +-- | Creates an interrupted ReaderT context+inReaderTCtx :: r -> a -> RSt (ReaderT r) a+inReaderTCtx r a = (a, r)++-- | Unwraps an interrupted WriterT context+peelReaderTCtx :: RSt (ReaderT r) a -> a+peelReaderTCtx (a, _) = a++instance Monoid w => Interruptible (RWST r w s) where+ type RSt (RWST r w s) a = (a, r, w, s)+ resume f (a, r, w, s) = do+ (a', s', w') <- runRWST (f a) r s+ return (a', r, w', s')++-- | Creates an interrupted RWST context+inRWSTCtx :: Monoid w => r -> s -> a -> RSt (RWST r w s) a+inRWSTCtx r s a = (a, r, mempty, s)++-- | Unwraps an interrupted RWST context+peelRWSTCtx :: RSt (RWST r w s) a -> (a, w, s)+peelRWSTCtx (a, r, w, s) = (a, w, s) resume2 :: (Monad m, Interruptible t, Monad (t m), Interruptible u) => (a -> u (t m) b) -> RSt t (RSt u a) -> m (RSt t (RSt u b))