git.iko.soy/typeable/transformers-lift
on master help sign in
13 files changed+351−77
since splitsnapshots
unifiedsplit
.gitignore+1 .travis.yml+24−10 LICENSE+2−2 README.md+5 src/Control/Monad/Trans/Lift/CallCC.hs+73−18 src/Control/Monad/Trans/Lift/Catch.hs+41−2 src/Control/Monad/Trans/Lift/Listen.hs+54−12 src/Control/Monad/Trans/Lift/Local.hs+42−6 src/Control/Monad/Trans/Lift/Pass.hs+55−12 src/Control/Monad/Trans/Lift/StT.hs+20−2 stack-7.8.3.yaml+7 stack.yaml+4 transformers-lift.cabal+23−13
.gitignore+1
@@ -1,3 +1,4 @@
11dist
2+.stack-work
23.cabal-sandbox/
34cabal.sandbox.config
.travis.yml+24−10
@@ -1,21 +1,35 @@
1+sudo: false
2+
13env:
2− - CABALVER=1.18 GHCVER=7.6.3
3− - CABALVER=1.18 GHCVER=7.8.4
4− - CABALVER=1.22 GHCVER=7.10.2
4+ - CABALVER=3.0 GHCVER=7.10.3
5+ - CABALVER=3.0 GHCVER=8.0.2
6+ - CABALVER=3.0 GHCVER=8.2.2
7+ - CABALVER=3.0 GHCVER=8.4.4
8+ - CABALVER=3.0 GHCVER=8.6.1
59 - CABALVER=head GHCVER=head
610
711before_install:
8− - travis_retry sudo add-apt-repository -y ppa:hvr/ghc
9− - travis_retry sudo apt-get update
10− - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
1112 - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
13+ - ghc --version
14+ - cabal --version
1215 - travis_retry cabal update
1316
1417install:
15− - cabal --version
16− - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
17− - cabal install --only-dependencies
18+ - cabal install --dep
1819
1920script:
20− - cabal configure --enable-tests -v2
2121 - cabal build
22+
23+addons:
24+ apt:
25+ sources:
26+ - hvr-ghc
27+ packages:
28+ - ghc-7.10.3
29+ - ghc-8.0.2
30+ - ghc-8.2.2
31+ - ghc-8.4.4
32+ - ghc-8.6.1
33+ - ghc-head
34+ - cabal-install-3.0
35+ - cabal-install-head
LICENSE+2−2
@@ -1,4 +1,4 @@
1−Copyright (c) 2015, Index Int
1+Copyright (c) 2015, Vladislav Zavialov
22
33All rights reserved.
44
@@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met:
1313 disclaimer in the documentation and/or other materials provided
1414 with the distribution.
1515
16− * Neither the name of Index Int nor the names of other
16+ * Neither the name of Vladislav Zavialov nor the names of other
1717 contributors may be used to endorse or promote products derived
1818 from this software without specific prior written permission.
1919
README.mdnew file+5
@@ -0,0 +1,5 @@
1+[![Build Status](https://img.shields.io/travis/int-index/transformers-lift.svg)](https://travis-ci.org/int-index/transformers-lift)
2+[![Hackage](https://img.shields.io/hackage/v/transformers-lift.svg)](https://hackage.haskell.org/package/transformers-lift)
3+
4+`transformers-lift` is a simple and lightweight library that provides type
5+classes for lifting operations through monad transformers.
src/Control/Monad/Trans/Lift/CallCC.hs+73−18
@@ -1,7 +1,6 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE TypeFamilies #-}
32{-# LANGUAGE RankNTypes #-}
4−{-# LANGUAGE UndecidableInstances #-}
3+-- | Lifting the @callCC@ operation.
54module Control.Monad.Trans.Lift.CallCC
65 ( LiftCallCC(..)
76 , CallCC
@@ -24,68 +23,124 @@ import qualified Control.Monad.Trans.Maybe as M
2423import qualified Control.Monad.Trans.Reader as R
2524import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
2625import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
26+import qualified Control.Monad.Trans.RWS.CPS as RWS.CPS
2727import qualified Control.Monad.Trans.State.Lazy as S.Lazy
2828import qualified Control.Monad.Trans.State.Strict as S.Strict
2929import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
3030import qualified Control.Monad.Trans.Writer.Strict as W.Strict
31+import qualified Control.Monad.Trans.Writer.CPS as W.CPS
32+
33+#if MIN_VERSION_transformers(0,5,3)
34+import qualified Control.Monad.Trans.Accum as Acc
35+#endif
3136
3237import Control.Monad.Trans.Lift.StT
3338
39+-- | The class of monad transformers capable of lifting 'callCC'.
3440class MonadTrans t => LiftCallCC t where
35− liftCallCC, liftCallCC'
36− :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
37−
38−defaultLiftCallCC, defaultLiftCallCC'
41+ -- | Lift the @callCC@ operation.
42+ -- Should satisfy the uniformity property
43+ --
44+ -- * @'lift' (f k) = f' ('lift' . k) => 'lift' (cf f) = 'liftCallCC' cf f'@
45+ --
46+ liftCallCC :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
47+
48+ -- | Lift the @callCC@ operation.
49+ -- This is an alternative version of 'liftCallCC' included for historical
50+ -- reasons. It has a different lifting behavior for the @StateT@ and @RWST@
51+ -- monad transformers. Matches what @mtl@ does but doesn't satisfy the
52+ -- uniformity property.
53+ liftCallCC' :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
54+ liftCallCC' = liftCallCC
55+
56+-- | Default definition for the 'liftCallCC' method.
57+defaultLiftCallCC
3958 :: (Monad m, LiftCallCC n)
4059 => (forall x . n m x -> t m x)
60+ -- ^ Monad constructor
4161 -> (forall o x . t o x -> n o x)
62+ -- ^ Monad deconstructor
4263 -> CallCC m (StT n a) (StT n b)
4364 -> CallCC (t m) a b
4465defaultLiftCallCC t unT callCC f
4566 = t $ liftCallCC callCC (\g -> (unT . f) (t . g))
67+
68+-- | Default definition for the 'liftCallCC'' method.
69+defaultLiftCallCC'
70+ :: (Monad m, LiftCallCC n)
71+ => (forall x . n m x -> t m x)
72+ -- ^ Monad constructor
73+ -> (forall o x . t o x -> n o x)
74+ -- ^ Monad deconstructor
75+ -> CallCC m (StT n a) (StT n b)
76+ -> CallCC (t m) a b
4677defaultLiftCallCC' t unT callCC f
4778 = t $ liftCallCC' callCC (\g -> (unT . f) (t . g))
4879
4980instance LiftCallCC (E.ExceptT e) where
5081 liftCallCC = E.liftCallCC
51− liftCallCC' = E.liftCallCC
82+ {-# INLINE liftCallCC #-}
5283
5384instance LiftCallCC I.IdentityT where
5485 liftCallCC = I.liftCallCC
55− liftCallCC' = I.liftCallCC
86+ {-# INLINE liftCallCC #-}
5687
5788instance LiftCallCC L.ListT where
5889 liftCallCC = L.liftCallCC
59− liftCallCC' = L.liftCallCC
90+ {-# INLINE liftCallCC #-}
6091
6192instance LiftCallCC M.MaybeT where
6293 liftCallCC = M.liftCallCC
63− liftCallCC' = M.liftCallCC
94+ {-# INLINE liftCallCC #-}
6495
6596instance LiftCallCC (R.ReaderT r) where
6697 liftCallCC = R.liftCallCC
67− liftCallCC' = R.liftCallCC
98+ {-# INLINE liftCallCC #-}
99+
100+instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
101+ liftCallCC = W.Lazy.liftCallCC
102+ {-# INLINE liftCallCC #-}
103+
104+instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
105+ liftCallCC = W.Strict.liftCallCC
106+ {-# INLINE liftCallCC #-}
107+
108+instance Monoid w => LiftCallCC (W.CPS.WriterT w) where
109+ liftCallCC = W.CPS.liftCallCC
110+ {-# INLINE liftCallCC #-}
68111
69112instance Monoid w => LiftCallCC (RWS.Lazy.RWST r w s) where
70113 liftCallCC = RWS.Lazy.liftCallCC
114+ {-# INLINE liftCallCC #-}
71115 liftCallCC' = RWS.Lazy.liftCallCC'
116+ {-# INLINE liftCallCC' #-}
72117
73118instance Monoid w => LiftCallCC (RWS.Strict.RWST r w s) where
74119 liftCallCC = RWS.Strict.liftCallCC
120+ {-# INLINE liftCallCC #-}
75121 liftCallCC' = RWS.Strict.liftCallCC'
122+ {-# INLINE liftCallCC' #-}
123+
124+instance Monoid w => LiftCallCC (RWS.CPS.RWST r w s) where
125+ liftCallCC = RWS.CPS.liftCallCC
126+ {-# INLINE liftCallCC #-}
127+ liftCallCC' = RWS.CPS.liftCallCC'
128+ {-# INLINE liftCallCC' #-}
76129
77130instance LiftCallCC (S.Lazy.StateT s) where
78131 liftCallCC = S.Lazy.liftCallCC
132+ {-# INLINE liftCallCC #-}
79133 liftCallCC' = S.Lazy.liftCallCC'
134+ {-# INLINE liftCallCC' #-}
80135
81136instance LiftCallCC (S.Strict.StateT s) where
82137 liftCallCC = S.Strict.liftCallCC
138+ {-# INLINE liftCallCC #-}
83139 liftCallCC' = S.Strict.liftCallCC'
140+ {-# INLINE liftCallCC' #-}
84141
85−instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
86− liftCallCC = W.Lazy.liftCallCC
87− liftCallCC' = W.Lazy.liftCallCC
88−
89−instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
90− liftCallCC = W.Strict.liftCallCC
91− liftCallCC' = W.Strict.liftCallCC
142+#if MIN_VERSION_transformers(0,5,3)
143+instance Monoid w => LiftCallCC (Acc.AccumT w) where
144+ liftCallCC = Acc.liftCallCC
145+ {-# INLINE liftCallCC #-}
146+#endif
src/Control/Monad/Trans/Lift/Catch.hs+41−2
@@ -1,7 +1,6 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE TypeFamilies #-}
32{-# LANGUAGE RankNTypes #-}
4−{-# LANGUAGE UndecidableInstances #-}
3+-- | Lifting the @catch@ operation.
54module Control.Monad.Trans.Lift.Catch
65 ( LiftCatch(..)
76 , Catch
@@ -23,52 +22,92 @@ import qualified Control.Monad.Trans.Maybe as M
2322import qualified Control.Monad.Trans.Reader as R
2423import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
2524import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
25+import qualified Control.Monad.Trans.RWS.CPS as RWS.CPS
2626import qualified Control.Monad.Trans.State.Lazy as S.Lazy
2727import qualified Control.Monad.Trans.State.Strict as S.Strict
2828import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
2929import qualified Control.Monad.Trans.Writer.Strict as W.Strict
30+import qualified Control.Monad.Trans.Writer.CPS as W.CPS
31+
32+#if MIN_VERSION_transformers(0,5,3)
33+import qualified Control.Monad.Trans.Accum as Acc
34+#endif
3035
3136import Control.Monad.Trans.Lift.StT
3237
38+-- | The class of monad transformers capable of lifting 'catch'.
3339class MonadTrans t => LiftCatch t where
40+ -- | Lift the @catch@ operation.
41+ -- Should satisfy the uniformity property
42+ --
43+ -- * @'lift' (cf m f) = 'liftCatch' ('lift' . cf) ('lift' f)@
44+ --
3445 liftCatch :: Monad m => Catch e m (StT t a) -> Catch e (t m) a
3546
47+-- | Default definition for the 'liftCatch' method.
3648defaultLiftCatch
3749 :: (Monad m, LiftCatch n)
3850 => (forall x . n m x -> t m x)
51+ -- ^ Monad constructor
3952 -> (forall o x . t o x -> n o x)
53+ -- ^ Monad deconstructor
4054 -> Catch e m (StT n a) -> Catch e (t m) a
4155defaultLiftCatch t unT f m h = t $ liftCatch f (unT m) (unT . h)
4256
4357instance LiftCatch (E.ExceptT e) where
4458 liftCatch f m h = E.ExceptT $ f (E.runExceptT m) (E.runExceptT . h)
59+ {-# INLINE liftCatch #-}
4560
4661instance LiftCatch I.IdentityT where
4762 liftCatch = I.liftCatch
63+ {-# INLINE liftCatch #-}
4864
4965instance LiftCatch L.ListT where
5066 liftCatch = L.liftCatch
67+ {-# INLINE liftCatch #-}
5168
5269instance LiftCatch M.MaybeT where
5370 liftCatch = M.liftCatch
71+ {-# INLINE liftCatch #-}
5472
5573instance LiftCatch (R.ReaderT r) where
5674 liftCatch = R.liftCatch
75+ {-# INLINE liftCatch #-}
5776
5877instance Monoid w => LiftCatch (RWS.Lazy.RWST r w s) where
5978 liftCatch = RWS.Lazy.liftCatch
79+ {-# INLINE liftCatch #-}
6080
6181instance Monoid w => LiftCatch (RWS.Strict.RWST r w s) where
6282 liftCatch = RWS.Strict.liftCatch
83+ {-# INLINE liftCatch #-}
84+
85+instance Monoid w => LiftCatch (RWS.CPS.RWST r w s) where
86+ liftCatch = RWS.CPS.liftCatch
87+ {-# INLINE liftCatch #-}
6388
6489instance LiftCatch (S.Lazy.StateT s) where
6590 liftCatch = S.Lazy.liftCatch
91+ {-# INLINE liftCatch #-}
6692
6793instance LiftCatch (S.Strict.StateT s) where
6894 liftCatch = S.Strict.liftCatch
95+ {-# INLINE liftCatch #-}
6996
7097instance Monoid w => LiftCatch (W.Lazy.WriterT w) where
7198 liftCatch = W.Lazy.liftCatch
99+ {-# INLINE liftCatch #-}
72100
73101instance Monoid w => LiftCatch (W.Strict.WriterT w) where
74102 liftCatch = W.Strict.liftCatch
103+ {-# INLINE liftCatch #-}
104+
105+instance Monoid w => LiftCatch (W.CPS.WriterT w) where
106+ liftCatch = W.CPS.liftCatch
107+ {-# INLINE liftCatch #-}
108+
109+#if MIN_VERSION_transformers(0,5,3)
110+instance Monoid w => LiftCatch (Acc.AccumT w) where
111+ liftCatch = Acc.liftCatch
112+ {-# INLINE liftCatch #-}
113+#endif
src/Control/Monad/Trans/Lift/Listen.hs+54−12
@@ -1,7 +1,6 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE UndecidableInstances #-}
42{-# LANGUAGE RankNTypes #-}
3+-- | Lifting the @listen@ operation.
54module Control.Monad.Trans.Lift.Listen
65 ( LiftListen(..)
76 , Listen
@@ -16,63 +15,106 @@ import Data.Monoid
1615import Control.Monad.Signatures
1716import Control.Monad.Trans.Class
1817
19−import qualified Control.Monad.Trans.Except as E
20−import qualified Control.Monad.Trans.Identity as I
21−import qualified Control.Monad.Trans.Maybe as M
22−import qualified Control.Monad.Trans.Reader as R
23−import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
24−import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
25−import qualified Control.Monad.Trans.State.Lazy as S.Lazy
26−import qualified Control.Monad.Trans.State.Strict as S.Strict
27−import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
28−import qualified Control.Monad.Trans.Writer.Strict as W.Strict
18+import qualified Control.Monad.Trans.Except as E
19+import qualified Control.Monad.Trans.Identity as I
20+import qualified Control.Monad.Trans.Maybe as M
21+import qualified Control.Monad.Trans.Reader as R
22+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
23+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
24+import qualified Control.Monad.Trans.RWS.CPS.Internal as RWS.CPS
25+import qualified Control.Monad.Trans.State.Lazy as S.Lazy
26+import qualified Control.Monad.Trans.State.Strict as S.Strict
27+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
28+import qualified Control.Monad.Trans.Writer.Strict as W.Strict
29+import qualified Control.Monad.Trans.Writer.CPS.Internal as W.CPS
30+
31+#if MIN_VERSION_transformers(0,5,3)
32+import qualified Control.Monad.Trans.Accum as Acc
33+#endif
2934
3035import Control.Monad.Trans.Lift.StT
3136
37+-- | The class of monad transformers capable of lifting 'listen'.
3238class MonadTrans t => LiftListen t where
39+ -- | Lift the @listen@ operation.
40+ -- Should satisfy the uniformity property
41+ --
42+ -- * @'lift' . 'liftListen' = 'liftListen' . 'lift'@
43+ --
3344 liftListen :: Monad m => Listen w m (StT t a) -> Listen w (t m) a
3445
46+-- | Default definition for the `liftListen` method.
3547defaultLiftListen
3648 :: (Monad m, LiftListen n)
3749 => (forall x . n m x -> t m x)
50+ -- ^ Monad constructor
3851 -> (forall o x . t o x -> n o x)
52+ -- ^ Monad deconstructor
3953 -> Listen w m (StT n a) -> Listen w (t m) a
4054defaultLiftListen t unT listen m = t $ liftListen listen (unT m)
4155
4256instance LiftListen (E.ExceptT e) where
4357 liftListen = E.liftListen
58+ {-# INLINE liftListen #-}
4459
4560instance LiftListen I.IdentityT where
4661 liftListen = I.mapIdentityT
62+ {-# INLINE liftListen #-}
4763
4864instance LiftListen M.MaybeT where
4965 liftListen = M.liftListen
66+ {-# INLINE liftListen #-}
5067
5168instance LiftListen (R.ReaderT r) where
5269 liftListen = R.mapReaderT
70+ {-# INLINE liftListen #-}
5371
5472instance LiftListen (S.Lazy.StateT s) where
5573 liftListen = S.Lazy.liftListen
74+ {-# INLINE liftListen #-}
5675
5776instance LiftListen (S.Strict.StateT s) where
5877 liftListen = S.Strict.liftListen
78+ {-# INLINE liftListen #-}
5979
6080instance Monoid w' => LiftListen (RWS.Lazy.RWST r w' s) where
6181 liftListen listen m = RWS.Lazy.RWST $ \r s -> do
6282 ~((a, w', s'), w) <- listen (RWS.Lazy.runRWST m r s)
6383 return ((a, w), w', s')
84+ {-# INLINE liftListen #-}
6485
6586instance Monoid w' => LiftListen (RWS.Strict.RWST r w' s) where
6687 liftListen listen m = RWS.Strict.RWST $ \r s -> do
6788 ((a, w', s'), w) <- listen (RWS.Strict.runRWST m r s)
6889 return ((a, w), w', s')
90+ {-# INLINE liftListen #-}
91+
92+instance Monoid w' => LiftListen (RWS.CPS.RWST r w' s) where
93+ liftListen listen m = RWS.CPS.RWST $ \r w_ s -> do
94+ ((a, w', s'), w) <- listen (RWS.CPS.unRWST m r w_ s)
95+ return ((a, w), w', s')
96+ {-# INLINE liftListen #-}
6997
7098instance Monoid w' => LiftListen (W.Lazy.WriterT w') where
7199 liftListen listen m = W.Lazy.WriterT $ do
72100 ~((a, w'), w) <- listen (W.Lazy.runWriterT m)
73101 return ((a, w), w')
102+ {-# INLINE liftListen #-}
74103
75104instance Monoid w' => LiftListen (W.Strict.WriterT w') where
76105 liftListen listen m = W.Strict.WriterT $ do
77106 ((a, w'), w) <- listen (W.Strict.runWriterT m)
78107 return ((a, w), w')
108+ {-# INLINE liftListen #-}
109+
110+instance Monoid w' => LiftListen (W.CPS.WriterT w') where
111+ liftListen listen m = W.CPS.WriterT $ \w_ -> do
112+ ((a, w'), w) <- listen (W.CPS.unWriterT m w_)
113+ return ((a, w), w')
114+ {-# INLINE liftListen #-}
115+
116+#if MIN_VERSION_transformers(0,5,3)
117+instance Monoid w' => LiftListen (Acc.AccumT w') where
118+ liftListen = Acc.liftListen
119+ {-# INLINE liftListen #-}
120+#endif
src/Control/Monad/Trans/Lift/Local.hs+42−6
@@ -1,6 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
3−{-# LANGUAGE DefaultSignatures #-}
3+-- | Lifting the 'local' operation.
44module Control.Monad.Trans.Lift.Local
55 ( LiftLocal(..)
66 , Local
@@ -22,24 +22,34 @@ import qualified Control.Monad.Trans.Maybe as M
2222import qualified Control.Monad.Trans.Reader as R
2323import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
2424import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
25+import qualified Control.Monad.Trans.RWS.CPS as RWS.CPS
2526import qualified Control.Monad.Trans.State.Lazy as S.Lazy
2627import qualified Control.Monad.Trans.State.Strict as S.Strict
2728import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
2829import qualified Control.Monad.Trans.Writer.Strict as W.Strict
30+import qualified Control.Monad.Trans.Writer.CPS as W.CPS
2931
32+#if MIN_VERSION_transformers(0,5,3)
33+import qualified Control.Monad.Trans.Accum as Acc
34+#endif
35+
36+-- | Signature of the @local@ operation,
37+-- introduced in "Control.Monad.Trans.Reader".
3038type Local r m a = (r -> r) -> m a -> m a
3139
40+-- | The class of monad transformers capable of lifting 'local'.
3241class MonadTrans t => LiftLocal t where
33− liftLocal
34− :: Monad m
35− => m r
36− -> (forall a . Local r m a)
37− -> (forall a . Local r (t m) a)
42+ -- | Lift the 'local' operation.
43+ liftLocal :: Monad m => m r -> (forall a . Local r m a)
44+ -> (forall a . Local r (t m) a)
3845
46+-- | Default definition for the 'liftLocal' method.
3947defaultLiftLocal
4048 :: (Monad m, LiftLocal n)
4149 => (forall x . n m x -> t m x)
50+ -- ^ Monad constructor
4251 -> (forall o x . t o x -> n o x)
52+ -- ^ Monad deconstructor
4353 -> m r
4454 -> (forall a . Local r m a)
4555 -> (forall a . Local r (t m) a)
@@ -47,36 +57,62 @@ defaultLiftLocal t unT a l f = t . liftLocal a l f . unT
4757
4858instance LiftLocal (C.ContT r) where
4959 liftLocal a l f = C.liftLocal a l f
60+ {-# INLINE liftLocal #-}
5061
5162instance LiftLocal (E.ExceptT e) where
5263 liftLocal _ l f = E.mapExceptT (l f)
64+ {-# INLINE liftLocal #-}
5365
5466instance LiftLocal I.IdentityT where
5567 liftLocal _ l f = I.mapIdentityT (l f)
68+ {-# INLINE liftLocal #-}
5669
5770instance LiftLocal L.ListT where
5871 liftLocal _ l f = L.mapListT (l f)
72+ {-# INLINE liftLocal #-}
5973
6074instance LiftLocal M.MaybeT where
6175 liftLocal _ l f = M.mapMaybeT (l f)
76+ {-# INLINE liftLocal #-}
6277
6378instance LiftLocal (R.ReaderT r) where
6479 liftLocal _ l f = R.mapReaderT (l f)
80+ {-# INLINE liftLocal #-}
6581
6682instance Monoid w => LiftLocal (RWS.Lazy.RWST r w s) where
6783 liftLocal _ l f = RWS.Lazy.mapRWST (l f)
84+ {-# INLINE liftLocal #-}
6885
6986instance Monoid w => LiftLocal (RWS.Strict.RWST r w s) where
7087 liftLocal _ l f = RWS.Strict.mapRWST (l f)
88+ {-# INLINE liftLocal #-}
89+
90+instance Monoid w => LiftLocal (RWS.CPS.RWST r w s) where
91+ liftLocal _ l f = RWS.CPS.mapRWST (l f)
92+ {-# INLINE liftLocal #-}
7193
7294instance LiftLocal (S.Lazy.StateT s) where
7395 liftLocal _ l f = S.Lazy.mapStateT (l f)
96+ {-# INLINE liftLocal #-}
7497
7598instance LiftLocal (S.Strict.StateT s) where
7699 liftLocal _ l f = S.Strict.mapStateT (l f)
100+ {-# INLINE liftLocal #-}
77101
78102instance Monoid w => LiftLocal (W.Lazy.WriterT w) where
79103 liftLocal _ l f = W.Lazy.mapWriterT (l f)
104+ {-# INLINE liftLocal #-}
80105
81106instance Monoid w => LiftLocal (W.Strict.WriterT w) where
82107 liftLocal _ l f = W.Strict.mapWriterT (l f)
108+ {-# INLINE liftLocal #-}
109+
110+instance Monoid w => LiftLocal (W.CPS.WriterT w) where
111+ liftLocal _ l f = W.CPS.mapWriterT (l f)
112+ {-# INLINE liftLocal #-}
113+
114+#if MIN_VERSION_transformers(0,5,3)
115+instance Monoid w => LiftLocal (Acc.AccumT w) where
116+ liftLocal _ l f = Acc.mapAccumT (l f)
117+ {-# INLINE liftLocal #-}
118+#endif
src/Control/Monad/Trans/Lift/Pass.hs+55−12
@@ -1,7 +1,7 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE TypeFamilies #-}
32{-# LANGUAGE RankNTypes #-}
4−{-# LANGUAGE UndecidableInstances #-}
3+
4+-- | Lifting the 'pass' operation.
55module Control.Monad.Trans.Lift.Pass
66 ( LiftPass(..)
77 , Pass
@@ -16,64 +16,107 @@ import Data.Monoid
1616import Control.Monad.Signatures
1717import Control.Monad.Trans.Class
1818
19−import qualified Control.Monad.Trans.Except as E
20−import qualified Control.Monad.Trans.Identity as I
21−import qualified Control.Monad.Trans.Maybe as M
22−import qualified Control.Monad.Trans.Reader as R
23−import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
24−import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
25−import qualified Control.Monad.Trans.State.Lazy as S.Lazy
26−import qualified Control.Monad.Trans.State.Strict as S.Strict
27−import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
28−import qualified Control.Monad.Trans.Writer.Strict as W.Strict
19+import qualified Control.Monad.Trans.Except as E
20+import qualified Control.Monad.Trans.Identity as I
21+import qualified Control.Monad.Trans.Maybe as M
22+import qualified Control.Monad.Trans.Reader as R
23+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
24+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
25+import qualified Control.Monad.Trans.RWS.CPS.Internal as RWS.CPS
26+import qualified Control.Monad.Trans.State.Lazy as S.Lazy
27+import qualified Control.Monad.Trans.State.Strict as S.Strict
28+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
29+import qualified Control.Monad.Trans.Writer.Strict as W.Strict
30+import qualified Control.Monad.Trans.Writer.CPS.Internal as W.CPS
31+
32+#if MIN_VERSION_transformers(0,5,3)
33+import qualified Control.Monad.Trans.Accum as Acc
34+#endif
2935
3036import Control.Monad.Trans.Lift.StT
3137
38+-- | The class of monad transformers capable of lifting 'pass'.
3239class MonadTrans t => LiftPass t where
40+ -- | Lift the 'pass' operation.
41+ -- Should satisfy the uniformity property
42+ --
43+ -- * @'lift' . 'liftPass' = 'liftPass' . 'lift'@
44+ --
3345 liftPass :: Monad m => Pass w m (StT t a) -> Pass w (t m) a
3446
47+-- | Default definition for the 'liftPass' method.
3548defaultLiftPass
3649 :: (Monad m, LiftPass n)
3750 => (forall x . n m x -> t m x)
51+ -- ^ Monad constructor
3852 -> (forall o x . t o x -> n o x)
53+ -- ^ Monad deconstructor
3954 -> Pass w m (StT n a)
4055 -> Pass w (t m) a
4156defaultLiftPass t unT pass m = t $ liftPass pass (unT m)
4257
4358instance LiftPass (E.ExceptT e) where
4459 liftPass = E.liftPass
60+ {-# INLINE liftPass #-}
4561
4662instance LiftPass I.IdentityT where
4763 liftPass = I.mapIdentityT
64+ {-# INLINE liftPass #-}
4865
4966instance LiftPass M.MaybeT where
5067 liftPass = M.liftPass
68+ {-# INLINE liftPass #-}
5169
5270instance LiftPass (R.ReaderT r) where
5371 liftPass = R.mapReaderT
72+ {-# INLINE liftPass #-}
5473
5574instance LiftPass (S.Lazy.StateT s) where
5675 liftPass = S.Lazy.liftPass
76+ {-# INLINE liftPass #-}
5777
5878instance LiftPass (S.Strict.StateT s) where
5979 liftPass = S.Strict.liftPass
80+ {-# INLINE liftPass #-}
6081
6182instance Monoid w' => LiftPass (RWS.Lazy.RWST r w' s) where
6283 liftPass pass m = RWS.Lazy.RWST $ \r s -> pass $ do
6384 ~((a, f), w', s') <- RWS.Lazy.runRWST m r s
6485 return ((a, w', s'), f)
86+ {-# INLINE liftPass #-}
6587
6688instance Monoid w' => LiftPass (RWS.Strict.RWST r w' s) where
6789 liftPass pass m = RWS.Strict.RWST $ \r s -> pass $ do
6890 ((a, f), w', s') <- RWS.Strict.runRWST m r s
6991 return ((a, w', s'), f)
92+ {-# INLINE liftPass #-}
93+
94+instance Monoid w' => LiftPass (RWS.CPS.RWST r w' s) where
95+ liftPass pass m = RWS.CPS.RWST $ \r w_ s -> pass $ do
96+ ((a, f), w', s') <- RWS.CPS.unRWST m r w_ s
97+ return ((a, w', s'), f)
98+ {-# INLINE liftPass #-}
7099
71100instance Monoid w' => LiftPass (W.Lazy.WriterT w') where
72101 liftPass pass m = W.Lazy.WriterT $ pass $ do
73102 ~((a, f), w') <- W.Lazy.runWriterT m
74103 return ((a, w'), f)
104+ {-# INLINE liftPass #-}
75105
76106instance Monoid w' => LiftPass (W.Strict.WriterT w') where
77107 liftPass pass m = W.Strict.WriterT $ pass $ do
78108 ((a, f), w') <- W.Strict.runWriterT m
79109 return ((a, w'), f)
110+ {-# INLINE liftPass #-}
111+
112+instance Monoid w' => LiftPass (W.CPS.WriterT w') where
113+ liftPass pass m = W.CPS.WriterT $ \w_ -> pass $ do
114+ ((a, f), w') <- W.CPS.unWriterT m w_
115+ return ((a, w'), f)
116+ {-# INLINE liftPass #-}
117+
118+#if MIN_VERSION_transformers(0,5,3)
119+instance Monoid w' => LiftPass (Acc.AccumT w') where
120+ liftPass = Acc.liftPass
121+ {-# INLINE liftPass #-}
122+#endif
src/Control/Monad/Trans/Lift/StT.hs+20−2
@@ -1,6 +1,9 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE TypeFamilies #-}
23{-# LANGUAGE KindSignatures #-}
3−module Control.Monad.Trans.Lift.StT where
4+
5+-- | The 'StT' type family.
6+module Control.Monad.Trans.Lift.StT (StT) where
47
58import qualified Control.Monad.Trans.Except as E
69import qualified Control.Monad.Trans.Identity as I
@@ -9,12 +12,21 @@ import qualified Control.Monad.Trans.Maybe as M
912import qualified Control.Monad.Trans.Reader as R
1013import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
1114import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
15+import qualified Control.Monad.Trans.RWS.CPS as RWS.CPS
1216import qualified Control.Monad.Trans.State.Lazy as S.Lazy
1317import qualified Control.Monad.Trans.State.Strict as S.Strict
1418import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
1519import qualified Control.Monad.Trans.Writer.Strict as W.Strict
20+import qualified Control.Monad.Trans.Writer.CPS as W.CPS
21+
22+#if MIN_VERSION_transformers(0,5,3)
23+import qualified Control.Monad.Trans.Accum as Acc
24+#endif
1625
26+-- | Internal state of a monad transformer.
27+-- Same as @StT@ from the @monad-control@ package.
1728type family StT (t :: (* -> *) -> (* -> *)) (a :: *) :: *
29+
1830type instance StT (E.ExceptT e) a = Either e a
1931type instance StT I.IdentityT a = a
2032type instance StT L.ListT a = [a]
@@ -22,7 +34,13 @@ type instance StT M.MaybeT a = Maybe a
2234type instance StT (R.ReaderT r) a = a
2335type instance StT (RWS.Lazy.RWST r w s) a = (a, s, w)
2436type instance StT (RWS.Strict.RWST r w s) a = (a, s, w)
37+type instance StT (RWS.CPS.RWST r w s) a = (a, s, w)
2538type instance StT (S.Lazy.StateT s) a = (a, s)
2639type instance StT (S.Strict.StateT s) a = (a, s)
27−type instance StT (W.Strict.WriterT w) a = (a, w)
2840type instance StT (W.Lazy.WriterT w) a = (a, w)
41+type instance StT (W.Strict.WriterT w) a = (a, w)
42+type instance StT (W.CPS.WriterT w) a = (a, w)
43+
44+#if MIN_VERSION_transformers(0,5,3)
45+type instance StT (Acc.AccumT w) a = (a, w)
46+#endif
stack-7.8.3.yamlnew file+7
@@ -0,0 +1,7 @@
1+flags: {}
2+packages:
3+- '.'
4+resolver: lts-2.22
5+extra-deps:
6+- transformers-0.4.2.0
7+- writer-cps-transformers-0.1.1.3
stack.yamlnew file+4
@@ -0,0 +1,4 @@
1+flags: {}
2+packages:
3+- '.'
4+resolver: nightly-2018-03-17
transformers-lift.cabal+23−13
@@ -1,16 +1,19 @@
1+cabal-version: 2.2
12name: transformers-lift
2−version: 0.0.0.0
3+version: 0.2.0.2
34synopsis: Ad-hoc type classes for lifting
4−-- description:
5−license: BSD3
5+description:
6+ This simple and lightweight library provides type classes
7+ for lifting monad transformer operations.
8+
9+-- license: BSD3
10+-- ^ unfortunately have to comment this line because of cabal2nix
611license-file: LICENSE
7−author: Index Int
8−maintainer: vlad.z.4096@gmail.com
9−-- copyright:
12+author: Vladislav Zavialov
13+maintainer: Vladislav Zavialov <vlad.z.4096@gmail.com>
1014category: Control
15+bug-reports: https://github.com/int-index/transformers-lift/issues
1116build-type: Simple
12−-- extra-source-files:
13−cabal-version: >=1.10
1417
1518library
1619 exposed-modules: Control.Monad.Trans.Lift.Local
@@ -19,12 +22,19 @@ library
1922 Control.Monad.Trans.Lift.Listen
2023 Control.Monad.Trans.Lift.Pass
2124 Control.Monad.Trans.Lift.StT
22− -- other-modules:
23− build-depends: base >=4.6 && <4.9
24− , transformers >= 0.4.2
25+
26+ build-depends: base >=4.8 && <4.13
27+ , transformers >= 0.4.2.0 && <0.6
28+ , writer-cps-transformers == 0.1.1.4
29+
30+ mixins: transformers hiding
31+ (Control.Monad.Trans.RWS.CPS, Control.Monad.Trans.Writer.CPS)
2532
2633 default-language: Haskell2010
27− -- other-extensions:
34+ other-extensions: CPP
35+ RankNTypes
36+ TypeFamilies
37+ KindSignatures
2838
2939 hs-source-dirs: src
30− ghc-options: -Wall
40+ ghc-options: -Wall -fno-warn-deprecations