@@ -1,5 +1,5 @@
1−module Ether.Handler
1+module Ether.TaggedTrans
2− ( Handler(..)
2+ ( TaggedTrans(..)
5import Control.Applicative
5import Control.Applicative
@@ -29,109 +29,114 @@ import qualified Control.Monad.Error.Class as Mtl
29import GHC.Generics (Generic)
29import GHC.Generics (Generic)
30import Data.Coerce (coerce)
30import Data.Coerce (coerce)
32−newtype Handler eff trans m a = Handler (trans m a)
32+newtype TaggedTrans tag trans m a = TaggedTrans (trans m a)
35 , Functor, Applicative, Alternative, Monad, MonadPlus
35 , Functor, Applicative, Alternative, Monad, MonadPlus
36 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
36 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
37 , MonadThrow, MonadCatch, MonadMask )
37 , MonadThrow, MonadCatch, MonadMask )
39−type Pack eff trans m a = trans m a -> Handler eff trans m a
39+type Pack tag trans m a = trans m a -> TaggedTrans tag trans m a
41−type Unpack eff trans m a = Handler eff trans m a -> trans m a
41+type Unpack tag trans m a = TaggedTrans tag trans m a -> trans m a
44 ( MB.MonadBase b (trans m)
44 ( MB.MonadBase b (trans m)
45− ) => MB.MonadBase b (Handler eff trans m)
45+ ) => MB.MonadBase b (TaggedTrans tag trans m)
47 liftBase =
47 liftBase =
48 (coerce :: forall a .
48 (coerce :: forall a .
49 (b a -> trans m a) ->
49 (b a -> trans m a) ->
50− (b a -> Handler eff trans m a))
50+ (b a -> TaggedTrans tag trans m a))
51 MB.liftBase
51 MB.liftBase
52+ {-# INLINE liftBase #-}
54 ( MC.MonadTransControl trans
55 ( MC.MonadTransControl trans
55− ) => MC.MonadTransControl (Handler eff trans)
56+ ) => MC.MonadTransControl (TaggedTrans tag trans)
57− type StT (Handler eff trans) a = MC.StT trans a
58+ type StT (TaggedTrans tag trans) a = MC.StT trans a
58 liftWith = MC.defaultLiftWith
60 liftWith = MC.defaultLiftWith
59− (coerce :: Pack eff trans m a)
61+ (coerce :: Pack tag trans m a)
60− (coerce :: Unpack eff trans m a)
62+ (coerce :: Unpack tag trans m a)
63+ {-# INLINE liftWith #-}
61 restoreT = MC.defaultRestoreT
65 restoreT = MC.defaultRestoreT
62− (coerce :: Pack eff trans m a)
66+ (coerce :: Pack tag trans m a)
67+ {-# INLINE restoreT #-}
64type LiftBaseWith b m a = (MC.RunInBase m b -> b a) -> m a
69type LiftBaseWith b m a = (MC.RunInBase m b -> b a) -> m a
66newtype LiftBaseWith' b m a = LBW { unLBW :: LiftBaseWith b m a }
71newtype LiftBaseWith' b m a = LBW { unLBW :: LiftBaseWith b m a }
68coerceLiftBaseWith ::
73coerceLiftBaseWith ::
69− LiftBaseWith b (trans m) a ->
74+ LiftBaseWith b (trans m) a ->
70− LiftBaseWith b (Handler eff trans m) a
75+ LiftBaseWith b (TaggedTrans tag trans m) a
71coerceLiftBaseWith lbw =
76coerceLiftBaseWith lbw =
72 unLBW (coerce (LBW lbw))
77 unLBW (coerce (LBW lbw))
73{-# INLINE coerceLiftBaseWith #-}
78{-# INLINE coerceLiftBaseWith #-}
76 ( MC.MonadBaseControl b (trans m)
81 ( MC.MonadBaseControl b (trans m)
77− ) => MC.MonadBaseControl b (Handler eff trans m)
82+ ) => MC.MonadBaseControl b (TaggedTrans tag trans m)
79− type StM (Handler eff trans m) a = MC.StM (trans m) a
84+ type StM (TaggedTrans tag trans m) a = MC.StM (trans m) a
81 liftBaseWith = coerceLiftBaseWith MC.liftBaseWith
86 liftBaseWith = coerceLiftBaseWith MC.liftBaseWith
82 {-# INLINE liftBaseWith #-}
87 {-# INLINE liftBaseWith #-}
84 restoreM =
89 restoreM =
85 (coerce :: forall a .
90 (coerce :: forall a .
86− (MC.StM (trans m) a -> trans m a) ->
91+ (MC.StM (trans m) a -> trans m a) ->
87− (MC.StM (trans m) a -> Handler eff trans m a))
92+ (MC.StM (trans m) a -> TaggedTrans tag trans m a))
88 MC.restoreM
93 MC.restoreM
89 {-# INLINE restoreM #-}
94 {-# INLINE restoreM #-}
91−type instance Lift.StT (Handler eff trans) a = Lift.StT trans a
96+type instance Lift.StT (TaggedTrans tag trans) a = Lift.StT trans a
93−instance Lift.LiftLocal trans => Lift.LiftLocal (Handler eff trans) where
98+instance Lift.LiftLocal trans => Lift.LiftLocal (TaggedTrans tag trans) where
94 liftLocal =
99 liftLocal =
95 Lift.defaultLiftLocal
100 Lift.defaultLiftLocal
96− (coerce :: Pack eff trans m a)
101+ (coerce :: Pack tag trans m a)
97− (coerce :: Unpack eff trans m a)
102+ (coerce :: Unpack tag trans m a)
99−instance Lift.LiftCatch trans => Lift.LiftCatch (Handler eff trans) where
104+instance Lift.LiftCatch trans => Lift.LiftCatch (TaggedTrans tag trans) where
100 liftCatch =
105 liftCatch =
101 Lift.defaultLiftCatch
106 Lift.defaultLiftCatch
102− (coerce :: Pack eff trans m a)
107+ (coerce :: Pack tag trans m a)
103− (coerce :: Unpack eff trans m a)
108+ (coerce :: Unpack tag trans m a)
105−instance Lift.LiftListen trans => Lift.LiftListen (Handler eff trans) where
110+instance Lift.LiftListen trans => Lift.LiftListen (TaggedTrans tag trans) where
106 liftListen =
111 liftListen =
107 Lift.defaultLiftListen
112 Lift.defaultLiftListen
108− (coerce :: Pack eff trans m a)
113+ (coerce :: Pack tag trans m a)
109− (coerce :: Unpack eff trans m a)
114+ (coerce :: Unpack tag trans m a)
111−instance Lift.LiftPass trans => Lift.LiftPass (Handler eff trans) where
116+instance Lift.LiftPass trans => Lift.LiftPass (TaggedTrans tag trans) where
112 liftPass =
117 liftPass =
113 Lift.defaultLiftPass
118 Lift.defaultLiftPass
114− (coerce :: Pack eff trans m a)
119+ (coerce :: Pack tag trans m a)
115− (coerce :: Unpack eff trans m a)
120+ (coerce :: Unpack tag trans m a)
117−instance Lift.LiftCallCC trans => Lift.LiftCallCC (Handler eff trans) where
122+instance Lift.LiftCallCC trans => Lift.LiftCallCC (TaggedTrans tag trans) where
118 liftCallCC =
123 liftCallCC =
119 Lift.defaultLiftCallCC
124 Lift.defaultLiftCallCC
120− (coerce :: Pack eff trans m a)
125+ (coerce :: Pack tag trans m a)
121− (coerce :: Unpack eff trans m a)
126+ (coerce :: Unpack tag trans m a)
122 liftCallCC' =
127 liftCallCC' =
123 Lift.defaultLiftCallCC'
128 Lift.defaultLiftCallCC'
124− (coerce :: Pack eff trans m a)
129+ (coerce :: Pack tag trans m a)
125− (coerce :: Unpack eff trans m a)
130+ (coerce :: Unpack tag trans m a)
128−-- Instances for mtl Mtles
133+-- Instances for mtl classes
130instance {-# OVERLAPPABLE #-}
135instance {-# OVERLAPPABLE #-}
131 ( Mtl.MonadCont m
136 ( Mtl.MonadCont m
132 , Lift.LiftCallCC trans
137 , Lift.LiftCallCC trans
133 , Monad (trans m)
138 , Monad (trans m)
134− ) => Mtl.MonadCont (Handler eff trans m)
139+ ) => Mtl.MonadCont (TaggedTrans tag trans m)
136 callCC = Lift.liftCallCC' Mtl.callCC
141 callCC = Lift.liftCallCC' Mtl.callCC
@@ -139,7 +144,7 @@ instance {-# OVERLAPPABLE #-}
139 ( Mtl.MonadReader r m
144 ( Mtl.MonadReader r m
140 , Lift.LiftLocal trans
145 , Lift.LiftLocal trans
141 , Monad (trans m)
146 , Monad (trans m)
142− ) => Mtl.MonadReader r (Handler eff trans m)
147+ ) => Mtl.MonadReader r (TaggedTrans tag trans m)
144 ask = lift Mtl.ask
149 ask = lift Mtl.ask
145 local = Lift.liftLocal Mtl.ask Mtl.local
150 local = Lift.liftLocal Mtl.ask Mtl.local
@@ -149,7 +154,7 @@ instance {-# OVERLAPPABLE #-}
149 ( Mtl.MonadState s m
154 ( Mtl.MonadState s m
150 , MonadTrans trans
155 , MonadTrans trans
151 , Monad (trans m)
156 , Monad (trans m)
152− ) => Mtl.MonadState s (Handler eff trans m)
157+ ) => Mtl.MonadState s (TaggedTrans tag trans m)
154 get = lift Mtl.get
159 get = lift Mtl.get
155 put = lift . Mtl.put
160 put = lift . Mtl.put
@@ -160,7 +165,7 @@ instance {-# OVERLAPPABLE #-}
160 , Lift.LiftListen trans
165 , Lift.LiftListen trans
161 , Lift.LiftPass trans
166 , Lift.LiftPass trans
162 , Monad (trans m)
167 , Monad (trans m)
163− ) => Mtl.MonadWriter w (Handler eff trans m)
168+ ) => Mtl.MonadWriter w (TaggedTrans tag trans m)
165 writer = lift . Mtl.writer
170 writer = lift . Mtl.writer
166 tell = lift . Mtl.tell
171 tell = lift . Mtl.tell
@@ -171,7 +176,7 @@ instance {-# OVERLAPPABLE #-}
171 ( Mtl.MonadError e m
176 ( Mtl.MonadError e m
172 , Lift.LiftCatch trans
177 , Lift.LiftCatch trans
173 , Monad (trans m)
178 , Monad (trans m)
174− ) => Mtl.MonadError e (Handler eff trans m)
179+ ) => Mtl.MonadError e (TaggedTrans tag trans m)
176 throwError = lift . Mtl.throwError
181 throwError = lift . Mtl.throwError
177 catchError = Lift.liftCatch Mtl.catchError
182 catchError = Lift.liftCatch Mtl.catchError