@@ -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