packages feed

contstuff 1.1.0 → 1.2.0

raw patch · 6 files changed

+129/−29 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.ContStuff.Classes: class Readable m where { type family StateOf m; }
+ Control.ContStuff.Instances: instance (Monad m, Readable m) => Readable (ChoiceT r i m)
+ Control.ContStuff.Instances: instance (Monad m, Readable m) => Readable (ContT r m)
+ Control.ContStuff.Instances: instance (Monad m, Readable m) => Readable (EitherT r e m)
+ Control.ContStuff.Instances: instance (Monad m, Readable m) => Readable (IdentityT m)
+ Control.ContStuff.Instances: instance (Monad m, Readable m) => Readable (MaybeT r m)
+ Control.ContStuff.Monads: runReader :: e -> Reader e a -> a
+ Control.ContStuff.Monads: type Reader e a = ReaderT e Identity a
+ Control.ContStuff.Simple: data ReaderT e m a
+ Control.ContStuff.Simple: runReaderT :: Applicative m => e -> ReaderT e m a -> m a
+ Control.ContStuff.Trans: data ReaderT e m a
+ Control.ContStuff.Trans: instance Applicative (ReaderT e m)
+ Control.ContStuff.Trans: instance Forkable m => Forkable (ReaderT e m)
+ Control.ContStuff.Trans: instance Functor (ReaderT e m)
+ Control.ContStuff.Trans: instance Monad (ReaderT e m)
+ Control.ContStuff.Trans: instance MonadIO m => MonadIO (ReaderT e m)
+ Control.ContStuff.Trans: instance MonadTrans (ReaderT e)
+ Control.ContStuff.Trans: instance Readable (ReaderT e m)
+ Control.ContStuff.Trans: instance Readable (StateT r s m)
+ Control.ContStuff.Trans: runReaderT :: Applicative m => e -> ReaderT e m a -> m a
- Control.ContStuff.Classes: class Stateful m where { type family StateOf m; { put x = x `seq` putLazy x } }
+ Control.ContStuff.Classes: class Stateful m
- Control.ContStuff.Classes: get :: Stateful m => m (StateOf m)
+ Control.ContStuff.Classes: get :: Readable m => m (StateOf m)
- Control.ContStuff.Classes: getField :: (Functor m, Stateful m) => (StateOf m -> a) -> m a
+ Control.ContStuff.Classes: getField :: (Functor m, Readable m) => (StateOf m -> a) -> m a
- Control.ContStuff.Classes: modify :: (Monad m, Stateful m) => (StateOf m -> StateOf m) -> m ()
+ Control.ContStuff.Classes: modify :: (Monad m, Readable m, Stateful m) => (StateOf m -> StateOf m) -> m ()
- Control.ContStuff.Classes: modifyField :: (Monad m, Stateful m) => (StateOf m -> a) -> (a -> StateOf m) -> m ()
+ Control.ContStuff.Classes: modifyField :: (Monad m, Readable m, Stateful m) => (StateOf m -> a) -> (a -> StateOf m) -> m ()
- Control.ContStuff.Classes: modifyFieldLazy :: (Monad m, Stateful m) => (StateOf m -> a) -> (a -> StateOf m) -> m ()
+ Control.ContStuff.Classes: modifyFieldLazy :: (Monad m, Readable m, Stateful m) => (StateOf m -> a) -> (a -> StateOf m) -> m ()
- Control.ContStuff.Classes: modifyLazy :: (Monad m, Stateful m) => (StateOf m -> StateOf m) -> m ()
+ Control.ContStuff.Classes: modifyLazy :: (Monad m, Readable m, Stateful m) => (StateOf m -> StateOf m) -> m ()

Files

Control/ContStuff/Classes.hs view
@@ -24,8 +24,12 @@       bracket, bracket_, catch, finally, forbid, handle, raiseUnless,       raiseWhen, require,       -- ** State+      -- *** Reading+      Readable(..),+      getField,+      -- *** Writing       Stateful(..),-      getField, modify, modifyField, modifyFieldLazy, modifyLazy,+      modify, modifyField, modifyFieldLazy, modifyLazy,       -- ** Logging support (writers)       Writable(..)     )@@ -209,17 +213,27 @@ -- State -- ----------- --- | Stateful monads.------ Minimal complete definition: 'StateOf', 'get' and 'putLazy'.+-- | Monads with environment (reader monads). -class Stateful m where-    -- | State type of @m@.+class Readable m where+    -- | Environment type of @m@.     type StateOf m      -- | Get the current state.     get :: m (StateOf m) ++-- | Get a certain field.++getField :: (Functor m, Readable m) => (StateOf m -> a) -> m a+getField = (<$> get)+++-- | Stateful monads, i.e. having a modifyable environment (stateful monads).+--+-- Minimal complete definition: 'putLazy'.++class Stateful m where     -- | Set the current state and force it.     put :: StateOf m -> m ()     put x = x `seq` putLazy x@@ -228,35 +242,30 @@     putLazy :: StateOf m -> m ()  --- | Get a certain field.--getField :: (Functor m, Stateful m) => (StateOf m -> a) -> m a-getField = (<$> get)-- -- | Apply a function to the current state. -modify :: (Monad m, Stateful m) => (StateOf m -> StateOf m) -> m ()+modify :: (Monad m, Readable m, Stateful m) => (StateOf m -> StateOf m) -> m () modify f = liftM f get >>= put   -- | Get a field and modify the state. -modifyField :: (Monad m, Stateful m) =>+modifyField :: (Monad m, Readable m, Stateful m) =>                (StateOf m -> a) -> (a -> StateOf m) -> m () modifyField accessor f = liftM (f . accessor) get >>= put   -- | Get a field and modify the state.  Lazy version. -modifyFieldLazy :: (Monad m, Stateful m) =>+modifyFieldLazy :: (Monad m, Readable m, Stateful m) =>                    (StateOf m -> a) -> (a -> StateOf m) -> m () modifyFieldLazy accessor f = liftM (f . accessor) get >>= putLazy   -- | Apply a function to the current state.  Lazy version. -modifyLazy :: (Monad m, Stateful m) => (StateOf m -> StateOf m) -> m ()+modifyLazy :: (Monad m, Readable m, Stateful m) =>+              (StateOf m -> StateOf m) -> m () modifyLazy f = liftM f get >>= putLazy  
Control/ContStuff/Instances.hs view
@@ -38,35 +38,50 @@   ----------------- Stateful --+-- Readable -- -------------- -instance (Monad m, Stateful m) => Stateful (ChoiceT r i m) where+instance (Monad m, Readable m) => Readable (ChoiceT r i m) where     type StateOf (ChoiceT r i m) = StateOf m     get = lift get++instance (Monad m, Readable m) => Readable (ContT r m) where+    type StateOf (ContT r m) = StateOf m+    get = lift get++instance (Monad m, Readable m) => Readable (EitherT r e m) where+    type StateOf (EitherT r e m) = StateOf m+    get = lift get++instance (Monad m, Readable m) => Readable (IdentityT m) where+    type StateOf (IdentityT m) = StateOf m+    get = lift get++instance (Monad m, Readable m) => Readable (MaybeT r m) where+    type StateOf (MaybeT r m) = StateOf m+    get = lift get+++--------------+-- Stateful --+--------------++instance (Monad m, Stateful m) => Stateful (ChoiceT r i m) where     put = lift . put     putLazy = lift . putLazy  instance (Monad m, Stateful m) => Stateful (ContT r m) where-    type StateOf (ContT r m) = StateOf m-    get = lift get     put = lift . put     putLazy = lift . putLazy  instance (Monad m, Stateful m) => Stateful (EitherT r e m) where-    type StateOf (EitherT r e m) = StateOf m-    get = lift get     put = lift . put     putLazy = lift . putLazy  instance (Monad m, Stateful m) => Stateful (IdentityT m) where-    type StateOf (IdentityT m) = StateOf m-    get = lift get     put = lift . put     putLazy = lift . putLazy  instance (Monad m, Stateful m) => Stateful (MaybeT r m) where-    type StateOf (MaybeT r m) = StateOf m-    get = lift get     put = lift . put     putLazy = lift . putLazy
Control/ContStuff/Monads.hs view
@@ -14,6 +14,8 @@       Choice, listChoice, maybeChoice,       -- ** Cont       Cont, runCont, evalCont, modifyCont,+      -- ** Reader+      Reader, runReader,       -- ** State       State, runState, evalState, execState,       -- ** Writer@@ -100,6 +102,21 @@  execOldWriter :: Monoid w => OldWriter r w r -> w execOldWriter = snd . runIdentity . runOldWriterT+++------------+-- Reader --+------------++-- | Pure computation with environment.++type Reader e a = ReaderT e Identity a+++-- | Run a pure computation with environment.++runReader :: e -> Reader e a -> a+runReader env = runIdentity . runReaderT env   -----------
Control/ContStuff/Simple.hs view
@@ -24,6 +24,10 @@       MaybeT,       evalMaybeT, testMaybeT, +      -- * Reader+      ReaderT,+      runReaderT,+       -- * State       StateT,       evalStateT, execStateT,@@ -43,6 +47,7 @@ import Control.Applicative import Control.ContStuff.Classes import Control.ContStuff.Instances ()+import Control.ContStuff.Trans (ReaderT, runReaderT) import Control.Monad import Data.Monoid 
Control/ContStuff/Trans.hs view
@@ -8,7 +8,11 @@ -- This module implements a number of monad transformers using a CPS -- approach internally. -{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-}+{-# LANGUAGE+  FlexibleInstances,+  MultiParamTypeClasses,+  RankNTypes,+  TypeFamilies #-}  module Control.ContStuff.Trans     ( -- * Monad transformers@@ -32,6 +36,9 @@       runMaybeT, evalMaybeT, modifyMaybeT, testMaybeT,        -- ** State+      ReaderT,+      runReaderT,+       StateT(..),       runStateT, evalStateT, execStateT, @@ -469,6 +476,51 @@ execOldWriterT = fmap snd . runOldWriterT  +-------------+-- ReaderT --+-------------++-- | Monad transformer for computations with readable environment.+-- Unlike the other monad transformers this one allows no CPS effects,+-- which makes it commutative.+--+-- If you need CPS effects, consider using 'StateT'.++newtype ReaderT e m a =+    ReaderT { getReaderT :: forall r. StateT r e m a }++instance Applicative (ReaderT e m) where+    pure = return+    ReaderT cf <*> ReaderT cx = ReaderT (cf <*> cx)++instance Forkable m => Forkable (ReaderT e m) where+    forkIO (ReaderT c) = ReaderT (forkIO c)++instance Functor (ReaderT e m) where+    fmap f (ReaderT c) = ReaderT (fmap f c)++instance Monad (ReaderT e m) where+    return x = ReaderT (return x)+    ReaderT c >>= f =+        ReaderT (c >>= getReaderT . f)++instance MonadIO m => MonadIO (ReaderT e m) where+    liftIO c = ReaderT (liftIO c)++instance Readable (ReaderT e m) where+    type StateOf (ReaderT e m) = e+    get = ReaderT get++instance MonadTrans (ReaderT e) where+    lift c = ReaderT (lift c)+++-- | Run a computation with environment.++runReaderT :: Applicative m => e -> ReaderT e m a -> m a+runReaderT x (ReaderT s) = evalStateT x s++ ------------ -- StateT -- ------------@@ -519,9 +571,11 @@     mzero = empty     mplus = (<|>) -instance Stateful (StateT r s m) where+instance Readable (StateT r s m) where     type StateOf (StateT r s m) = s     get = StateT $ \s0 k -> k s0 s0++instance Stateful (StateT r s m) where     put s1 = s1 `seq` StateT $ \_ k -> k s1 ()     putLazy s1 = StateT $ \_ k -> k s1 () 
contstuff.cabal view
@@ -1,5 +1,5 @@ Name:          contstuff-Version:       1.1.0+Version:       1.2.0 Category:      Control, Monads Synopsis:      Fast, easy to use CPS-based monad transformers Maintainer:    Ertugrul Söylemez <es@ertes.de>