packages feed

writer-cps-transformers 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+76/−63 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Control.Monad.Trans.RWS.CPS: ask :: Applicative m => RWST r w s m r
+ Control.Monad.Trans.RWS.CPS: ask :: Monad m => RWST r w s m r
- Control.Monad.Trans.RWS.CPS: asks :: Applicative m => (r -> a) -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: asks :: Monad m => (r -> a) -> RWST r w s m a
- Control.Monad.Trans.RWS.CPS: censor :: (Monoid w, Functor m) => (w -> w) -> RWST r w s m a -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: censor :: (Monoid w, Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a
- Control.Monad.Trans.RWS.CPS: evalRWST :: (Functor m, Monoid w) => RWST r w s m a -> r -> s -> m (a, w)
+ Control.Monad.Trans.RWS.CPS: evalRWST :: (Monad m, Monoid w) => RWST r w s m a -> r -> s -> m (a, w)
- Control.Monad.Trans.RWS.CPS: execRWST :: (Functor m, Monoid w) => RWST r w s m a -> r -> s -> m (s, w)
+ Control.Monad.Trans.RWS.CPS: execRWST :: (Monad m, Monoid w) => RWST r w s m a -> r -> s -> m (s, w)
- Control.Monad.Trans.RWS.CPS: get :: Applicative m => RWST r w s m s
+ Control.Monad.Trans.RWS.CPS: get :: Monad m => RWST r w s m s
- Control.Monad.Trans.RWS.CPS: gets :: Applicative m => (s -> a) -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: gets :: Monad m => (s -> a) -> RWST r w s m a
- Control.Monad.Trans.RWS.CPS: listen :: (Monoid w, Functor m) => RWST r w s m a -> RWST r w s m (a, w)
+ Control.Monad.Trans.RWS.CPS: listen :: (Monoid w, Monad m) => RWST r w s m a -> RWST r w s m (a, w)
- Control.Monad.Trans.RWS.CPS: listens :: (Monoid w, Functor m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
+ Control.Monad.Trans.RWS.CPS: listens :: (Monoid w, Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
- Control.Monad.Trans.RWS.CPS: mapRWST :: (Functor n, Monoid w, Monoid w') => (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
+ Control.Monad.Trans.RWS.CPS: mapRWST :: (Monad n, Monoid w, Monoid w') => (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
- Control.Monad.Trans.RWS.CPS: modify :: Applicative m => (s -> s) -> RWST r w s m ()
+ Control.Monad.Trans.RWS.CPS: modify :: Monad m => (s -> s) -> RWST r w s m ()
- Control.Monad.Trans.RWS.CPS: pass :: (Monoid w, Monoid w', Functor m) => RWST r w s m (a, w -> w') -> RWST r w' s m a
+ Control.Monad.Trans.RWS.CPS: pass :: (Monoid w, Monoid w', Monad m) => RWST r w s m (a, w -> w') -> RWST r w' s m a
- Control.Monad.Trans.RWS.CPS: put :: Applicative m => s -> RWST r w s m ()
+ Control.Monad.Trans.RWS.CPS: put :: Monad m => s -> RWST r w s m ()
- Control.Monad.Trans.RWS.CPS: reader :: Applicative m => (r -> a) -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: reader :: Monad m => (r -> a) -> RWST r w s m a
- Control.Monad.Trans.RWS.CPS: state :: Applicative m => (s -> (a, s)) -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: state :: Monad m => (s -> (a, s)) -> RWST r w s m a
- Control.Monad.Trans.RWS.CPS: tell :: (Monoid w, Applicative m) => w -> RWST r w s m ()
+ Control.Monad.Trans.RWS.CPS: tell :: (Monoid w, Monad m) => w -> RWST r w s m ()
- Control.Monad.Trans.RWS.CPS: writer :: (Monoid w, Applicative m) => (a, w) -> RWST r w s m a
+ Control.Monad.Trans.RWS.CPS: writer :: (Monoid w, Monad m) => (a, w) -> RWST r w s m a
- Control.Monad.Trans.Writer.CPS: censor :: (Monoid w, Functor m) => (w -> w) -> WriterT w m a -> WriterT w m a
+ Control.Monad.Trans.Writer.CPS: censor :: (Monoid w, Monad m) => (w -> w) -> WriterT w m a -> WriterT w m a
- Control.Monad.Trans.Writer.CPS: execWriterT :: (Functor m, Monoid w) => WriterT w m a -> m w
+ Control.Monad.Trans.Writer.CPS: execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w
- Control.Monad.Trans.Writer.CPS: listen :: (Monoid w, Functor m) => WriterT w m a -> WriterT w m (a, w)
+ Control.Monad.Trans.Writer.CPS: listen :: (Monoid w, Monad m) => WriterT w m a -> WriterT w m (a, w)
- Control.Monad.Trans.Writer.CPS: listens :: (Monoid w, Functor m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b)
+ Control.Monad.Trans.Writer.CPS: listens :: (Monoid w, Monad m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b)
- Control.Monad.Trans.Writer.CPS: mapWriterT :: (Functor n, Monoid w, Monoid w') => (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
+ Control.Monad.Trans.Writer.CPS: mapWriterT :: (Monad n, Monoid w, Monoid w') => (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- Control.Monad.Trans.Writer.CPS: pass :: (Monoid w, Monoid w', Functor m) => WriterT w m (a, w -> w') -> WriterT w' m a
+ Control.Monad.Trans.Writer.CPS: pass :: (Monoid w, Monoid w', Monad m) => WriterT w m (a, w -> w') -> WriterT w' m a
- Control.Monad.Trans.Writer.CPS: tell :: (Monoid w, Applicative m) => w -> WriterT w m ()
+ Control.Monad.Trans.Writer.CPS: tell :: (Monoid w, Monad m) => w -> WriterT w m ()
- Control.Monad.Trans.Writer.CPS: writer :: (Monoid w, Applicative m) => (a, w) -> WriterT w m a
+ Control.Monad.Trans.Writer.CPS: writer :: (Monoid w, Monad m) => (a, w) -> WriterT w m a

Files

Control/Monad/Trans/RWS/CPS.hs view
@@ -60,7 +60,7 @@ -- | Construct an RWS computation from a function. -- (The inverse of 'runRWS'.) rws :: Monoid w => (r -> s -> (a, s, w)) -> RWS r w s a-rws f = RWST (\r s w -> let (a, s', w') = f r s; wt = w `mappend` w' in wt `seq` pure (a, s', wt))+rws f = RWST (\r s w -> let (a, s', w') = f r s; wt = w `mappend` w' in wt `seq` return (a, s', wt)) {-# INLINE rws #-}  -- | Unwrap an RWS computation as a function.@@ -122,32 +122,38 @@  -- | Evaluate a computation with the given initial state and environment, -- returning the final value and output, discarding the final state.-evalRWST :: (Functor m, Monoid w)+evalRWST :: (Monad m, Monoid w)          => RWST r w s m a      -- ^computation to execute          -> r                   -- ^initial environment          -> s                   -- ^initial value          -> m (a, w)            -- ^computation yielding final value and output-evalRWST m r s = (\(a, _, w) -> (a, w)) <$> runRWST m r s+evalRWST m r s = do+    (a, _, w) <- runRWST m r s+    return (a, w) {-# INLINE evalRWST #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final state and output, discarding the final value.-execRWST :: (Functor m, Monoid w)+execRWST :: (Monad m, Monoid w)          => RWST r w s m a      -- ^computation to execute          -> r                   -- ^initial environment          -> s                   -- ^initial value          -> m (s, w)            -- ^computation yielding final state and output-execRWST m r s = (\(_, s', w) -> (s', w)) <$> runRWST m r s+execRWST m r s = do+    (_, s', w) <- runRWST m r s+    return (s', w) {-# INLINE execRWST #-}  -- | Map the inner computation using the given function. -- -- * @'runRWST' ('mapRWST' f m) r s = f ('runRWST' m r s)@ --mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b-mapRWST :: (Functor n, Monoid w, Monoid w')+mapRWST :: (Monad n, Monoid w, Monoid w')   => (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b-mapRWST f m = RWST $ \r s w -> (\(a, s', w') -> let wt = w `mappend` w'-                                                in wt `seq` (a, s', wt)) <$> f (runRWST m r s)+mapRWST f m = RWST $ \r s w -> do+  (a, s', w') <- f (runRWST m r s)+  let wt = w `mappend` w'+  wt `seq` return (a, s', wt) {-# INLINE mapRWST #-}  -- | @'withRWST' f m@ executes action @m@ with an initial environment@@ -222,12 +228,12 @@ -- Reader operations  -- | Constructor for computations in the reader monad (equivalent to 'asks').-reader :: Applicative m => (r -> a) -> RWST r w s m a+reader :: Monad m => (r -> a) -> RWST r w s m a reader = asks {-# INLINE reader #-}  -- | Fetch the value of the environment.-ask :: Applicative m => RWST r w s m r+ask :: Monad m => RWST r w s m r ask = asks id {-# INLINE ask #-} @@ -241,20 +247,20 @@ -- | Retrieve a function of the current environment. -- -- * @'asks' f = 'liftM' f 'ask'@-asks :: Applicative m => (r -> a) -> RWST r w s m a-asks f = RWST $ \r s w -> pure (f r, s, w)+asks :: Monad m => (r -> a) -> RWST r w s m a+asks f = RWST $ \r s w -> return (f r, s, w) {-# INLINE asks #-}  -- --------------------------------------------------------------------------- -- Writer operations  -- | Construct a writer computation from a (result, output) pair.-writer :: (Monoid w, Applicative m) => (a, w) -> RWST r w s m a-writer (a, w') = RWST $ \_ s w -> let wt = w `mappend` w' in wt `seq` pure (a, s, wt)+writer :: (Monoid w, Monad m) => (a, w) -> RWST r w s m a+writer (a, w') = RWST $ \_ s w -> let wt = w `mappend` w' in wt `seq` return (a, s, wt) {-# INLINE writer #-}  -- | @'tell' w@ is an action that produces the output @w@.-tell :: (Monoid w, Applicative m) => w -> RWST r w s m ()+tell :: (Monoid w, Monad m) => w -> RWST r w s m () tell w' = writer ((), w') {-# INLINE tell #-} @@ -262,7 +268,7 @@ -- output to the value of the computation. -- -- * @'runRWST' ('listen' m) r s = 'liftM' (\\ (a, w) -> ((a, w), w)) ('runRWST' m r s)@-listen :: (Monoid w, Functor m) => RWST r w s m a -> RWST r w s m (a, w)+listen :: (Monoid w, Monad m) => RWST r w s m a -> RWST r w s m (a, w) listen = listens id {-# INLINE listen #-} @@ -272,11 +278,11 @@ -- * @'listens' f m = 'liftM' (id *** f) ('listen' m)@ -- -- * @'runRWST' ('listens' f m) r s = 'liftM' (\\ (a, w) -> ((a, f w), w)) ('runRWST' m r s)@-listens :: (Monoid w, Functor m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)-listens f m = RWST $ \r s w ->-  (\(a, s', w') ->-     let wt = w `mappend` w'-     in wt `seq` ((a, f w'), s', wt)) <$> runRWST m r s+listens :: (Monoid w, Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)+listens f m = RWST $ \r s w -> do+  (a, s', w') <- runRWST m r s+  let wt = w `mappend` w'+  wt `seq` return ((a, f w'), s', wt) {-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns@@ -284,11 +290,11 @@ -- to the output. -- -- * @'runRWST' ('pass' m) r s = 'liftM' (\\ ((a, f), w) -> (a, f w)) ('runRWST' m r s)@-pass :: (Monoid w, Monoid w', Functor m) => RWST r w s m (a, w -> w') -> RWST r w' s m a-pass m = RWST $ \r s w ->-  (\((a, f), s', w') ->-     let wt = w `mappend` f w'-     in wt `seq` (a, s', wt)) <$> runRWST m r s+pass :: (Monoid w, Monoid w', Monad m) => RWST r w s m (a, w -> w') -> RWST r w' s m a+pass m = RWST $ \r s w -> do+  ((a, f), s', w') <- runRWST m r s+  let wt = w `mappend` f w'+  wt `seq` return (a, s', wt) {-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and@@ -298,43 +304,43 @@ -- * @'censor' f m = 'pass' ('liftM' (\\ x -> (x,f)) m)@ -- -- * @'runRWST' ('censor' f m) r s = 'liftM' (\\ (a, w) -> (a, f w)) ('runRWST' m r s)@-censor :: (Monoid w, Functor m) => (w -> w) -> RWST r w s m a -> RWST r w s m a-censor f m = RWST $ \r s w ->-  (\(a, s', w') ->-     let wt = w `mappend` f w'-     in wt `seq` (a, s', wt)) <$> runRWST m r s+censor :: (Monoid w, Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a+censor f m = RWST $ \r s w -> do+  (a, s', w') <- runRWST m r s+  let wt = w `mappend` f w'+  wt `seq` return (a, s', wt) {-# INLINE censor #-}  -- --------------------------------------------------------------------------- -- State operations  -- | Construct a state monad computation from a state transformer function.-state :: Applicative m => (s -> (a, s)) -> RWST r w s m a-state f = RWST $ \_ s w -> let (a, s') = f s in pure (a, s', w)+state :: Monad m => (s -> (a, s)) -> RWST r w s m a+state f = RWST $ \_ s w -> let (a, s') = f s in return (a, s', w) {-# INLINE state #-}  -- | Fetch the current value of the state within the monad.-get :: Applicative m => RWST r w s m s+get :: Monad m => RWST r w s m s get = gets id {-# INLINE get #-}  -- | @'put' s@ sets the state within the monad to @s@.-put :: Applicative m => s -> RWST r w s m ()-put s = RWST $ \_ _ w -> pure ((), s, w)+put :: Monad m => s -> RWST r w s m ()+put s = RWST $ \_ _ w -> return ((), s, w) {-# INLINE put #-}  -- | @'modify' f@ is an action that updates the state to the result of -- applying @f@ to the current state. -- -- * @'modify' f = 'get' >>= ('put' . f)@-modify :: Applicative m => (s -> s) -> RWST r w s m ()-modify f = RWST $ \_ s w -> pure ((), f s, w)+modify :: Monad m => (s -> s) -> RWST r w s m ()+modify f = RWST $ \_ s w -> return ((), f s, w) {-# INLINE modify #-}  -- | Get a specific component of the state, using a projection function -- supplied. -- -- * @'gets' f = 'liftM' f 'get'@-gets :: Applicative m => (s -> a) -> RWST r w s m a-gets f = RWST $ \_ s w -> pure (f s, s, w)+gets :: Monad m => (s -> a) -> RWST r w s m a+gets f = RWST $ \_ s w -> return (f s, s, w) {-# INLINE gets #-}
Control/Monad/Trans/Writer/CPS.hs view
@@ -26,7 +26,6 @@ ) where  import Control.Applicative-import Control.Arrow (first, second) import Control.Monad import Control.Monad.Fix import Control.Monad.IO.Class@@ -47,8 +46,8 @@  -- | Construct a writer computation from a (result, output) pair. -- (The inverse of 'runWriter'.)-writer :: (Monoid w, Applicative m) => (a, w) -> WriterT w m a-writer (a, w') = WriterT $ \w -> let wt = w `mappend` w' in wt `seq` pure (a, wt)+writer :: (Monoid w, Monad m) => (a, w) -> WriterT w m a+writer (a, w') = WriterT $ \w -> let wt = w `mappend` w' in wt `seq` return (a, wt) {-# INLINE writer #-}  -- | Unwrap a writer computation as a (result, output) pair.@@ -91,21 +90,26 @@ -- | Extract the output from a writer computation. -- -- * @'execWriterT' m = 'liftM' 'snd' ('runWriterT' m)@-execWriterT :: (Functor m, Monoid w) => WriterT w m a -> m w-execWriterT = fmap snd . runWriterT+execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w+execWriterT m = do+  (_, w) <- runWriterT m+  return w {-# INLINE execWriterT #-}  -- | Map both the return value and output of a computation using -- the given function. -- -- * @'runWriterT' ('mapWriterT' f m) = f ('runWriterT' m)@-mapWriterT :: (Functor n, Monoid w, Monoid w') =>+mapWriterT :: (Monad n, Monoid w, Monoid w') =>   (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b-mapWriterT f m = WriterT $ \w -> second (mappend w) <$> f (runWriterT m)+mapWriterT f m = WriterT $ \w -> do+  (a, w') <- f (runWriterT m)+  let wt = w `mappend` w'+  wt `seq` return (a, wt) {-# INLINE mapWriterT #-}  instance Functor m => Functor (WriterT w m) where-  fmap f m = WriterT $ \w -> first f <$> unWriterT m w+  fmap f m = WriterT $ \w -> (\(a, w) -> (f a, w)) <$> unWriterT m w   {-# INLINE fmap #-}  instance (Functor m, Monad m) => Applicative (WriterT w m) where@@ -166,7 +170,7 @@   {-# INLINE liftIO #-}  -- | @'tell' w@ is an action that produces the output @w@.-tell :: (Monoid w, Applicative m) => w -> WriterT w m ()+tell :: (Monoid w, Monad m) => w -> WriterT w m () tell w = writer ((), w) {-# INLINE tell #-} @@ -174,7 +178,7 @@ -- output to the value of the computation. -- -- * @'runWriterT' ('listen' m) = 'liftM' (\\ (a, w) -> ((a, w), w)) ('runWriterT' m)@-listen :: (Monoid w, Functor m) => WriterT w m a -> WriterT w m (a, w)+listen :: (Monoid w, Monad m) => WriterT w m a -> WriterT w m (a, w) listen = listens id {-# INLINE listen #-} @@ -184,10 +188,11 @@ -- * @'listens' f m = 'liftM' (id *** f) ('listen' m)@ -- -- * @'runWriterT' ('listens' f m) = 'liftM' (\\ (a, w) -> ((a, f w), w)) ('runWriterT' m)@-listens :: (Monoid w, Functor m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b)-listens f m = WriterT $ \w ->-  (\(a, w') -> let wt = w `mappend` w'-               in wt `seq` ((a, f w'), wt)) <$> runWriterT m+listens :: (Monoid w, Monad m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b)+listens f m = WriterT $ \w -> do+  (a, w') <- runWriterT m+  let wt = w `mappend` w'+  wt `seq` return ((a, f w'), wt) {-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns@@ -195,10 +200,11 @@ -- to the output. -- -- * @'runWriterT' ('pass' m) = 'liftM' (\\ ((a, f), w) -> (a, f w)) ('runWriterT' m)@-pass :: (Monoid w, Monoid w', Functor m) => WriterT w m (a, w -> w') -> WriterT w' m a-pass m = WriterT $ \w ->-  (\((a, f), w') -> let wt = w `mappend` f w'-                    in wt `seq` (a, wt)) <$> runWriterT m+pass :: (Monoid w, Monoid w', Monad m) => WriterT w m (a, w -> w') -> WriterT w' m a+pass m = WriterT $ \w -> do+  ((a, f), w') <- runWriterT m+  let wt = w `mappend` f w'+  wt `seq` return (a, wt) {-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and@@ -208,8 +214,9 @@ -- * @'censor' f m = 'pass' ('liftM' (\\ x -> (x,f)) m)@ -- -- * @'runWriterT' ('censor' f m) = 'liftM' (\\ (a, w) -> (a, f w)) ('runWriterT' m)@-censor :: (Monoid w, Functor m) => (w -> w) -> WriterT w m a -> WriterT w m a-censor f m = WriterT $ \w ->-  (\(a, w') -> let wt = w `mappend` f w'-               in wt `seq` (a, wt)) <$> runWriterT m+censor :: (Monoid w, Monad m) => (w -> w) -> WriterT w m a -> WriterT w m a+censor f m = WriterT $ \w -> do+  (a, w') <- runWriterT m+  let wt = w `mappend` f w'+  wt `seq` return (a, wt) {-# INLINE censor #-}
writer-cps-transformers.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           writer-cps-transformers-version:        0.1.0.0+version:        0.1.0.1 license:        MIT license-file:   LICENSE tested-with:    GHC == 7.0.4, GHC == 7.2.2, GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1