@@ -1,11 +1,9 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−{-# LANGUAGE RankNTypes #-}
2+{-# LANGUAGE TypeFamilies #-}
3−-- | Lifting the @callCC@ operation.
3+{-# LANGUAGE UndecidableInstances #-}
4module Control.Monad.Trans.Lift.CallCC
4module Control.Monad.Trans.Lift.CallCC
5 ( LiftCallCC(..)
5 ( LiftCallCC(..)
9 , module Control.Monad.Trans.Class
7 , module Control.Monad.Trans.Class
@@ -15,6 +13,7 @@ import Data.Monoid
16import Control.Monad.Signatures
14import Control.Monad.Signatures
17import Control.Monad.Trans.Class
15import Control.Monad.Trans.Class
16+import Control.Monad.Trans.Control
19import qualified Control.Monad.Trans.Except as E
18import qualified Control.Monad.Trans.Except as E
20import qualified Control.Monad.Trans.Identity as I
19import qualified Control.Monad.Trans.Identity as I
@@ -23,124 +22,51 @@ import qualified Control.Monad.Trans.Maybe as M
23import qualified Control.Monad.Trans.Reader as R
22import qualified Control.Monad.Trans.Reader as R
24import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
23import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy
25import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
24import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict
26−import qualified Control.Monad.Trans.RWS.CPS as RWS.CPS
27import qualified Control.Monad.Trans.State.Lazy as S.Lazy
25import qualified Control.Monad.Trans.State.Lazy as S.Lazy
28import qualified Control.Monad.Trans.State.Strict as S.Strict
26import qualified Control.Monad.Trans.State.Strict as S.Strict
29import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
27import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy
30import qualified Control.Monad.Trans.Writer.Strict as W.Strict
28import qualified Control.Monad.Trans.Writer.Strict as W.Strict
31−import qualified Control.Monad.Trans.Writer.CPS as W.CPS
33−#if MIN_VERSION_transformers(0,5,3)
34−import qualified Control.Monad.Trans.Accum as Acc
37−import Control.Monad.Trans.Lift.StT
39−-- | The class of monad transformers capable of lifting 'callCC'.
40class MonadTrans t => LiftCallCC t where
30class MonadTrans t => LiftCallCC t where
41− -- | Lift the @callCC@ operation.
31+ type CallCCStT t a
42− -- Should satisfy the uniformity property
32+ type CallCCStT t a = StT t a
44− -- * @'lift' (f k) = f' ('lift' . k) => 'lift' (cf f) = 'liftCallCC' cf f'@
46− liftCallCC :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b
33+ liftCallCC :: Monad m => CallCC m (CallCCStT t a) (CallCCStT t b) -> CallCC (t m) a b
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
34+ liftCallCC' :: Monad m => CallCC m (CallCCStT t a) (CallCCStT t b) -> CallCC (t m) a b
54 liftCallCC' = liftCallCC
35 liftCallCC' = liftCallCC
56−-- | Default definition for the 'liftCallCC' method.
58− :: (Monad m, LiftCallCC n)
59− => (forall x . n m x -> t m x)
60− -- ^ Monad constructor
61− -> (forall o x . t o x -> n o x)
62− -- ^ Monad deconstructor
63− -> CallCC m (StT n a) (StT n b)
65−defaultLiftCallCC t unT callCC f
66− = t $ liftCallCC callCC (\g -> (unT . f) (t . g))
68−-- | Default definition for the 'liftCallCC'' method.
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)
77−defaultLiftCallCC' t unT callCC f
78− = t $ liftCallCC' callCC (\g -> (unT . f) (t . g))
80instance LiftCallCC (E.ExceptT e) where
37instance LiftCallCC (E.ExceptT e) where
81− liftCallCC = E.liftCallCC
38+ liftCallCC = E.liftCallCC
82− {-# INLINE liftCallCC #-}
84instance LiftCallCC I.IdentityT where
40instance LiftCallCC I.IdentityT where
85− liftCallCC = I.liftCallCC
41+ liftCallCC = I.liftCallCC
86− {-# INLINE liftCallCC #-}
88instance LiftCallCC L.ListT where
43instance LiftCallCC L.ListT where
89− liftCallCC = L.liftCallCC
44+ liftCallCC = L.liftCallCC
90− {-# INLINE liftCallCC #-}
92instance LiftCallCC M.MaybeT where
46instance LiftCallCC M.MaybeT where
93− liftCallCC = M.liftCallCC
47+ liftCallCC = M.liftCallCC
94− {-# INLINE liftCallCC #-}
96instance LiftCallCC (R.ReaderT r) where
49instance LiftCallCC (R.ReaderT r) where
97− liftCallCC = R.liftCallCC
50+ liftCallCC = R.liftCallCC
98− {-# INLINE liftCallCC #-}
100−instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
101− liftCallCC = W.Lazy.liftCallCC
102− {-# INLINE liftCallCC #-}
104−instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
105− liftCallCC = W.Strict.liftCallCC
106− {-# INLINE liftCallCC #-}
108−instance Monoid w => LiftCallCC (W.CPS.WriterT w) where
109− liftCallCC = W.CPS.liftCallCC
110− {-# INLINE liftCallCC #-}
112instance Monoid w => LiftCallCC (RWS.Lazy.RWST r w s) where
52instance Monoid w => LiftCallCC (RWS.Lazy.RWST r w s) where
113 liftCallCC = RWS.Lazy.liftCallCC
53 liftCallCC = RWS.Lazy.liftCallCC
114− {-# INLINE liftCallCC #-}
115 liftCallCC' = RWS.Lazy.liftCallCC'
54 liftCallCC' = RWS.Lazy.liftCallCC'
116− {-# INLINE liftCallCC' #-}
118instance Monoid w => LiftCallCC (RWS.Strict.RWST r w s) where
56instance Monoid w => LiftCallCC (RWS.Strict.RWST r w s) where
119 liftCallCC = RWS.Strict.liftCallCC
57 liftCallCC = RWS.Strict.liftCallCC
120− {-# INLINE liftCallCC #-}
121 liftCallCC' = RWS.Strict.liftCallCC'
58 liftCallCC' = RWS.Strict.liftCallCC'
122− {-# INLINE liftCallCC' #-}
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' #-}
130instance LiftCallCC (S.Lazy.StateT s) where
60instance LiftCallCC (S.Lazy.StateT s) where
131 liftCallCC = S.Lazy.liftCallCC
61 liftCallCC = S.Lazy.liftCallCC
132− {-# INLINE liftCallCC #-}
133 liftCallCC' = S.Lazy.liftCallCC'
62 liftCallCC' = S.Lazy.liftCallCC'
134− {-# INLINE liftCallCC' #-}
136instance LiftCallCC (S.Strict.StateT s) where
64instance LiftCallCC (S.Strict.StateT s) where
137 liftCallCC = S.Strict.liftCallCC
65 liftCallCC = S.Strict.liftCallCC
138− {-# INLINE liftCallCC #-}
139 liftCallCC' = S.Strict.liftCallCC'
66 liftCallCC' = S.Strict.liftCallCC'
140− {-# INLINE liftCallCC' #-}
142−#if MIN_VERSION_transformers(0,5,3)
143−instance Monoid w => LiftCallCC (Acc.AccumT w) where
68+instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where
144− liftCallCC = Acc.liftCallCC
69+ liftCallCC = W.Lazy.liftCallCC
71+instance Monoid w => LiftCallCC (W.Strict.WriterT w) where
145− {-# INLINE liftCallCC #-}
72+ liftCallCC = W.Strict.liftCallCC