git.iko.soy/typeable/transformers-lift
on master help sign in
Documentation update
commit454decad1898f7b67505489984d194b3bbc9a2af authorIndex Int <vlad.z.4096@gmail.com> dateSun 12 Jul 2015, 00:31 (11 years ago) parent20a9f6a
7 files changed+90−28
src/Control/Monad/Trans/Lift/CallCC.hs+37−16 src/Control/Monad/Trans/Lift/Catch.hs+10 src/Control/Monad/Trans/Lift/Listen.hs+10 src/Control/Monad/Trans/Lift/Local.hs+10−5 src/Control/Monad/Trans/Lift/Pass.hs+10 src/Control/Monad/Trans/Lift/StT.hs+5−1 transformers-lift.cabal+8−6
src/Control/Monad/Trans/Lift/CallCC.hs+37−16
@@ -1,5 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Lift the @callCC@ operation.
34module Control.Monad.Trans.Lift.CallCC
45 ( LiftCallCC(..)
56 , CallCC
@@ -29,40 +30,67 @@ import qualified Control.Monad.Trans.Writer.Strict as W.Strict
2930
3031import Control.Monad.Trans.Lift.StT
3132
33+-- | The class of monad transformers capable of lifting 'callCC'.
3234class MonadTrans t => LiftCallCC t where
33− liftCallCC, liftCallCC'
34− :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
35−
36−defaultLiftCallCC, defaultLiftCallCC'
35+ -- | Lift the @callCC@ operation.
36+ -- Should satisfy the uniformity property
37+ --
38+ -- * @'lift' (f k) = f' ('lift' . k) => 'lift' (cf f) = 'liftCallCC' cf f'@
39+ --
40+ liftCallCC :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
41+
42+ -- | Lift the @callCC@ operation.
43+ -- This is an alternative version of 'liftCallCC' included for historical
44+ -- reasons. It has a different lifting behavior for the @StateT@ and @RWST@
45+ -- monad transformers. Matches what @mtl@ does but doesn't satisfy the
46+ -- uniformity property.
47+ liftCallCC' :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
48+ liftCallCC' = liftCallCC
49+
50+-- | Default definition for the 'liftCallCC' method.
51+defaultLiftCallCC
3752 :: (Monad m, LiftCallCC n)
3853 => (forall x . n m x -> t m x)
54+ -- ^ Monad constructor
3955 -> (forall o x . t o x -> n o x)
56+ -- ^ Monad deconstructor
4057 -> CallCC m (StT n a) (StT n b)
4158 -> CallCC (t m) a b
4259defaultLiftCallCC t unT callCC f
4360 = t $ liftCallCC callCC (\g -> (unT . f) (t . g))
61+
62+-- | Default definition for the 'liftCallCC'' method.
63+defaultLiftCallCC'
64+ :: (Monad m, LiftCallCC n)
65+ => (forall x . n m x -> t m x)
66+ -- ^ Monad constructor
67+ -> (forall o x . t o x -> n o x)
68+ -- ^ Monad deconstructor
69+ -> CallCC m (StT n a) (StT n b)
70+ -> CallCC (t m) a b
4471defaultLiftCallCC' t unT callCC f
4572 = t $ liftCallCC' callCC (\g -> (unT . f) (t . g))
4673
4774instance LiftCallCC (E.ExceptT e) where
4875 liftCallCC = E.liftCallCC
49− liftCallCC' = E.liftCallCC
5076
5177instance LiftCallCC I.IdentityT where
5278 liftCallCC = I.liftCallCC
53− liftCallCC' = I.liftCallCC
5479
5580instance LiftCallCC L.ListT where
5681 liftCallCC = L.liftCallCC
57− liftCallCC' = L.liftCallCC
5882
5983instance LiftCallCC M.MaybeT where
6084 liftCallCC = M.liftCallCC
61− liftCallCC' = M.liftCallCC
6285
6386instance LiftCallCC (R.ReaderT r) where
6487 liftCallCC = R.liftCallCC
65− liftCallCC' = R.liftCallCC
88+
89+instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
90+ liftCallCC = W.Lazy.liftCallCC
91+
92+instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
93+ liftCallCC = W.Strict.liftCallCC
6694
6795instance Monoid w => LiftCallCC (RWS.Lazy.RWST r w s) where
6896 liftCallCC = RWS.Lazy.liftCallCC
@@ -80,10 +108,3 @@ instance LiftCallCC (S.Strict.StateT s) where
80108 liftCallCC = S.Strict.liftCallCC
81109 liftCallCC' = S.Strict.liftCallCC'
82110
83−instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
84− liftCallCC = W.Lazy.liftCallCC
85− liftCallCC' = W.Lazy.liftCallCC
86−
87−instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
88− liftCallCC = W.Strict.liftCallCC
89− liftCallCC' = W.Strict.liftCallCC
src/Control/Monad/Trans/Lift/Catch.hs+10
@@ -1,5 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Lift the @catch@ operation.
34module Control.Monad.Trans.Lift.Catch
45 ( LiftCatch(..)
56 , Catch
@@ -28,13 +29,22 @@ import qualified Control.Monad.Trans.Writer.Strict as W.Strict
2829
2930import Control.Monad.Trans.Lift.StT
3031
32+-- | The class of monad transformers capable of lifting 'catch'.
3133class MonadTrans t => LiftCatch t where
34+ -- | Lift the @catch@ operation.
35+ -- Should satisfy the uniformity property
36+ --
37+ -- * @'lift' (cf m f) = 'liftCatch' ('lift' . cf) ('lift' f)@
38+ --
3239 liftCatch :: Monad m => Catch e m (StT t a) -> Catch e (t m) a
3340
41+-- | Default definition for the 'liftCatch' method.
3442defaultLiftCatch
3543 :: (Monad m, LiftCatch n)
3644 => (forall x . n m x -> t m x)
45+ -- ^ Monad constructor
3746 -> (forall o x . t o x -> n o x)
47+ -- ^ Monad deconstructor
3848 -> Catch e m (StT n a) -> Catch e (t m) a
3949defaultLiftCatch t unT f m h = t $ liftCatch f (unT m) (unT . h)
4050
src/Control/Monad/Trans/Lift/Listen.hs+10
@@ -1,5 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Lift the @listen@ operation.
34module Control.Monad.Trans.Lift.Listen
45 ( LiftListen(..)
56 , Listen
@@ -27,13 +28,22 @@ import qualified Control.Monad.Trans.Writer.Strict as W.Strict
2728
2829import Control.Monad.Trans.Lift.StT
2930
31+-- | The class of monad transformers capable of lifting 'listen'.
3032class MonadTrans t => LiftListen t where
33+ -- | Lift the @listen@ operation.
34+ -- Should satisfy the uniformity property
35+ --
36+ -- * @'lift' . 'liftListen' = 'liftListen' . 'lift'@
37+ --
3138 liftListen :: Monad m => Listen w m (StT t a) -> Listen w (t m) a
3239
40+-- | Default definition for the `liftListen` method.
3341defaultLiftListen
3442 :: (Monad m, LiftListen n)
3543 => (forall x . n m x -> t m x)
44+ -- ^ Monad constructor
3645 -> (forall o x . t o x -> n o x)
46+ -- ^ Monad deconstructor
3747 -> Listen w m (StT n a) -> Listen w (t m) a
3848defaultLiftListen t unT listen m = t $ liftListen listen (unT m)
3949
src/Control/Monad/Trans/Lift/Local.hs+10−5
@@ -1,5 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Lift the 'local' operation.
34module Control.Monad.Trans.Lift.Local
45 ( LiftLocal(..)
56 , Local
@@ -26,19 +27,23 @@ import qualified Control.Monad.Trans.State.Strict as S.Strict
2627import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
2728import qualified Control.Monad.Trans.Writer.Strict as W.Strict
2829
30+-- | Signature of the @local@ operation,
31+-- introduced in "Control.Monad.Trans.Reader".
2932type Local r m a = (r -> r) -> m a -> m a
3033
34+-- | The class of monad transformers capable of lifting 'local'.
3135class MonadTrans t => LiftLocal t where
32− liftLocal
33− :: Monad m
34− => m r
35− -> (forall a . Local r m a)
36− -> (forall a . Local r (t m) a)
36+ -- | Lift the 'local' operation.
37+ liftLocal :: Monad m => m r -> (forall a . Local r m a)
38+ -> (forall a . Local r (t m) a)
3739
40+-- | Default definition for the 'liftLocal' method.
3841defaultLiftLocal
3942 :: (Monad m, LiftLocal n)
4043 => (forall x . n m x -> t m x)
44+ -- ^ Monad constructor
4145 -> (forall o x . t o x -> n o x)
46+ -- ^ Monad deconstructor
4247 -> m r
4348 -> (forall a . Local r m a)
4449 -> (forall a . Local r (t m) a)
src/Control/Monad/Trans/Lift/Pass.hs+10
@@ -1,5 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Lift the 'pass' operation.
34module Control.Monad.Trans.Lift.Pass
45 ( LiftPass(..)
56 , Pass
@@ -27,13 +28,22 @@ import qualified Control.Monad.Trans.Writer.Strict as W.Strict
2728
2829import Control.Monad.Trans.Lift.StT
2930
31+-- | The class of monad transformers capable of lifting 'pass'.
3032class MonadTrans t => LiftPass t where
33+ -- | Lift the 'pass' operation.
34+ -- Should satisfy the uniformity property
35+ --
36+ -- * @'lift' . 'liftPass' = 'liftPass' . 'lift'@
37+ --
3138 liftPass :: Monad m => Pass w m (StT t a) -> Pass w (t m) a
3239
40+-- | Default definition for the 'liftPass' method.
3341defaultLiftPass
3442 :: (Monad m, LiftPass n)
3543 => (forall x . n m x -> t m x)
44+ -- ^ Monad constructor
3645 -> (forall o x . t o x -> n o x)
46+ -- ^ Monad deconstructor
3747 -> Pass w m (StT n a)
3848 -> Pass w (t m) a
3949defaultLiftPass t unT pass m = t $ liftPass pass (unT m)
src/Control/Monad/Trans/Lift/StT.hs+5−1
@@ -1,6 +1,7 @@
11{-# LANGUAGE TypeFamilies #-}
22{-# LANGUAGE KindSignatures #-}
3−module Control.Monad.Trans.Lift.StT where
3+-- | The 'StT' type family.
4+module Control.Monad.Trans.Lift.StT (StT) where
45
56import qualified Control.Monad.Trans.Except as E
67import qualified Control.Monad.Trans.Identity as I
@@ -14,7 +15,10 @@ import qualified Control.Monad.Trans.State.Strict as S.Strict
1415import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
1516import qualified Control.Monad.Trans.Writer.Strict as W.Strict
1617
18+-- | Internal state of a monad transformer.
19+-- Same as @StT@ from the @monad-control@ package.
1720type family StT (t :: (* -> *) -> (* -> *)) (a :: *) :: *
21+
1822type instance StT (E.ExceptT e) a = Either e a
1923type instance StT I.IdentityT a = a
2024type instance StT L.ListT a = [a]
transformers-lift.cabal+8−6
@@ -1,15 +1,17 @@
11name: transformers-lift
2−version: 0.0.0.0
2+version: 0.1.0.0
33synopsis: Ad-hoc type classes for lifting
4−-- description:
4+description:
5+ This simple and lightweight library provides type classes
6+ for lifting monad transformer operations.
7+
58license: BSD3
69license-file: LICENSE
710author: Index Int
8−maintainer: vlad.z.4096@gmail.com
9−-- copyright:
11+maintainer: Index Int <vlad.z.4096@gmail.com>
1012category: Control
13+bug-reports: https://github.com/int-index/transformers-lift/issues
1114build-type: Simple
12−-- extra-source-files:
1315cabal-version: >=1.10
1416
1517library
@@ -19,7 +21,7 @@ library
1921 Control.Monad.Trans.Lift.Listen
2022 Control.Monad.Trans.Lift.Pass
2123 Control.Monad.Trans.Lift.StT
22− -- other-modules:
24+
2325 build-depends: base >=4.6 && <4.9
2426 , transformers >= 0.4.2
2527