on master help sign in
Update tagging system
6bf12f9Index Int
src/Control/Ether/Tags.hs+81−30
@@ -4,8 +4,12 @@
4{-# LANGUAGE ConstraintKinds #-}
4{-# LANGUAGE ConstraintKinds #-}
5{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE UndecidableInstances #-}
7+{-# LANGUAGE MultiParamTypeClasses #-}
8+{-# LANGUAGE FunctionalDependencies #-}
7module Control.Ether.Tags
9module Control.Ether.Tags
10+ ( Taggable(..)
11+ , Tagged(..)
8− ( Tags
12+ , Tags
9 , UniqueTag
13 , UniqueTag
10 , UniqueTags
14 , UniqueTags
11 , ensureUniqueTags
15 , ensureUniqueTags
@@ -58,32 +62,79 @@ type family UniqueTags (m :: * -> *) :: Constraint where
58ensureUniqueTags :: UniqueTags m => m a -> m a
62ensureUniqueTags :: UniqueTags m => m a -> m a
59ensureUniqueTags = id
63ensureUniqueTags = id
60
64
61−-- |
65+type family MaybeToList (mt :: Maybe *) :: [*] where
66+ MaybeToList 'Nothing = '[]
67+ MaybeToList ('Just t) = '[t]
68+
69+type family (as :: [*]) ++ (bs :: [*]) :: [*] where
70+ '[] ++ bs = bs
71+ (a ': as) ++ bs = a ': (as ++ bs)
72+
73+-- | The 'Taggable' class defines the type families to manage tags in monad
74+-- transformer stacks. Its kind is restricted to @* -> *@ to prevent incorrect
75+-- instances.
76+class Taggable (m :: * -> *) where
77+
78+ -- | The 'Tag' type family equals @Nothing@ for most types, but for tagged
79+ -- monad transformers it equals @Just tag@.
80+ type Tag m :: Maybe *
81+ type instance Tag m = 'Nothing
82+
62−-- The 'Tags' type family returns a type-level list of all tags of its argument
83+ -- | The 'Tags'' type family returns a type-level list of the inner monad
63−-- @m@. Simple monads have no tags, monad transformers propagate the tags of
84+ -- of a monad transformer. Instances should be defined by passing the inner
64−-- their inner monads, and tagged monad transformers also add their own tag.
85+ -- monad to the 'Tags' type function.
65−type family Tags (m :: * -> *) :: [*]
86+ type Tags' m :: [*]
66−
87+ type instance Tags' m = '[]
88+
67−type instance Tags IO = '[]
89+instance Taggable IO
68−type instance Tags Identity = '[]
90+instance Taggable Identity
69−type instance Tags [] = '[]
91+
70−type instance Tags Maybe = '[]
92+instance Taggable Maybe
71−type instance Tags Last = '[]
93+instance Taggable Last
72−type instance Tags First = '[]
94+instance Taggable First
73−type instance Tags ((->) r) = '[]
95+instance Taggable ((->) r)
74−type instance Tags STM = '[]
96+instance Taggable STM
75−type instance Tags (Either e) = '[]
97+instance Taggable (Either e)
76−type instance Tags Proxy = '[]
98+instance Taggable Proxy
77−type instance Tags (Strict.ST s) = '[]
99+instance Taggable (Strict.ST s)
78−type instance Tags (Lazy.ST s) = '[]
100+instance Taggable (Lazy.ST s)
79−
101+
102+instance Taggable (Trans.ContT r m) where
80−type instance Tags (Trans.ContT r m) = Tags m
103+ type Tags' (Trans.ContT r m) = Tags m
104+
105+instance Taggable (Trans.ExceptT e m) where
81−type instance Tags (Trans.ExceptT e m) = Tags m
106+ type Tags' (Trans.ExceptT e m) = Tags m
107+
108+instance Taggable (Trans.IdentityT m) where
82−type instance Tags (Trans.IdentityT m) = Tags m
109+ type Tags' (Trans.IdentityT m) = Tags m
110+
111+instance Taggable (Trans.ListT m) where
83−type instance Tags (Trans.ListT m) = Tags m
112+ type Tags' (Trans.ListT m) = Tags m
113+
114+instance Taggable (Trans.MaybeT m) where
84−type instance Tags (Trans.MaybeT m) = Tags m
115+ type Tags' (Trans.MaybeT m) = Tags m
116+
117+instance Taggable (Trans.ReaderT r m) where
85−type instance Tags (Trans.ReaderT r m) = Tags m
118+ type Tags' (Trans.ReaderT r m) = Tags m
119+
120+instance Taggable (Trans.Lazy.StateT s m) where
86−type instance Tags (Trans.Lazy.StateT s m) = Tags m
121+ type Tags' (Trans.Lazy.StateT s m) = Tags m
122+
123+instance Taggable (Trans.Strict.StateT s m) where
87−type instance Tags (Trans.Strict.StateT s m) = Tags m
124+ type Tags' (Trans.Strict.StateT s m) = Tags m
125+
126+instance Taggable (Trans.Lazy.WriterT w m) where
88−type instance Tags (Trans.Lazy.WriterT w m) = Tags m
127+ type Tags' (Trans.Lazy.WriterT w m) = Tags m
128+
129+instance Taggable (Trans.Strict.WriterT w m) where
89−type instance Tags (Trans.Strict.WriterT w m) = Tags m
130+ type Tags' (Trans.Strict.WriterT w m) = Tags m
131+
132+-- | The 'Tags' type function combines the results of 'Tag' and 'Tags''.
133+type Tags (m :: * -> *) = MaybeToList (Tag m) ++ Tags' m
134+
135+-- | The 'Tagged' type class establishes a relationship between a tagged
136+-- monad transformer and its untagged counterpart.
137+class (Taggable m, Tag m ~ 'Just tag) => Tagged m tag | m -> tag where
138+ type Untagged m :: * -> *
139+ tagged :: proxy tag -> Untagged m a -> m a
140+ untagged :: proxy tag -> m a -> Untagged m a
src/Control/Monad/Trans/Ether/Except.hs+19−21
@@ -25,9 +25,6 @@ module Control.Monad.Trans.Ether.Except
25 , liftListen
25 , liftListen
26 , liftPass
26 , liftPass
27 , liftCatch
27 , liftCatch
28− -- * Wrapping operations
29− , tagWrap
30− , tagUnwrap
31 ) where
28 ) where
32
29
33import Data.Proxy (Proxy(Proxy))
30import Data.Proxy (Proxy(Proxy))
@@ -38,7 +35,7 @@ import Control.Monad (MonadPlus)
38import Control.Monad.Fix (MonadFix)
35import Control.Monad.Fix (MonadFix)
39import Control.Monad.Trans.Class (MonadTrans, lift)
36import Control.Monad.Trans.Class (MonadTrans, lift)
40import Control.Monad.IO.Class (MonadIO)
37import Control.Monad.IO.Class (MonadIO)
41−import Control.Ether.Tags (Tags)
38+import Control.Ether.Tags (Taggable(..), Tagged(..), Tags)
42import qualified Control.Ether.Util as Util
39import qualified Control.Ether.Util as Util
43
40
44import qualified Control.Monad.Signatures as Sig
41import qualified Control.Monad.Signatures as Sig
@@ -61,7 +58,7 @@ type Except tag e = ExceptT tag e Identity
61
58
62-- | Runs an 'Except' and returns either an exception or a normal value.
59-- | Runs an 'Except' and returns either an exception or a normal value.
63runExcept :: proxy tag -> Except tag e a -> Either e a
60runExcept :: proxy tag -> Except tag e a -> Either e a
64−runExcept t = Trans.runExcept . tagUnwrap t
61+runExcept t = Trans.runExcept . untagged t
65
62
66-- | The exception monad transformer.
63-- | The exception monad transformer.
67--
64--
@@ -72,26 +69,27 @@ newtype ExceptT tag e m a = ExceptT (Trans.ExceptT e m a)
72 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
69 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
73 , MonadFix, MonadTrans, MonadIO )
70 , MonadFix, MonadTrans, MonadIO )
74
71
75−tagWrap :: proxy tag -> Trans.ExceptT e m a -> ExceptT tag e m a
72+instance Taggable (ExceptT tag e m) where
76−tagWrap _ = ExceptT
73+ type Tag (ExceptT tag e m) = 'Just tag
74+ type Tags' (ExceptT tag e m) = Tags m
77
75
76+instance Tagged (ExceptT tag e m) tag where
78−tagUnwrap :: proxy tag -> ExceptT tag e m a -> Trans.ExceptT e m a
77+ type Untagged (ExceptT tag e m) = Trans.ExceptT e m
79−tagUnwrap _ (ExceptT a) = a
78+ tagged _ = ExceptT
80−
79+ untagged _ (ExceptT a) = a
81−type instance Tags (ExceptT tag r m) = tag ': Tags m
82
80
83-- | Constructor for computations in the exception monad transformer.
81-- | Constructor for computations in the exception monad transformer.
84exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a
82exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a
85−exceptT t = tagWrap t . Trans.ExceptT
83+exceptT t = tagged t . Trans.ExceptT
86
84
87-- | Constructor for computations in the exception monad
85-- | Constructor for computations in the exception monad
88-- (the inverse of 'runExcept').
86-- (the inverse of 'runExcept').
89except :: proxy tag -> Either e a -> Except tag e a
87except :: proxy tag -> Either e a -> Except tag e a
90−except t = tagWrap t . Trans.except
88+except t = tagged t . Trans.except
91
89
92-- | Runs an 'ExceptT' and returns either an exception or a normal value.
90-- | Runs an 'ExceptT' and returns either an exception or a normal value.
93runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a)
91runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a)
94−runExceptT t = Trans.runExceptT . tagUnwrap t
92+runExceptT t = Trans.runExceptT . untagged t
95
93
96-- | Transforms the computation inside an 'ExceptT'.
94-- | Transforms the computation inside an 'ExceptT'.
97--
95--
@@ -101,29 +99,29 @@ mapExceptT
101 -> (m (Either e a) -> n (Either e' b))
99 -> (m (Either e a) -> n (Either e' b))
102 -> ExceptT tag e m a
100 -> ExceptT tag e m a
103 -> ExceptT tag e' n b
101 -> ExceptT tag e' n b
104−mapExceptT t f m = tagWrap t $ Trans.mapExceptT f (coerce m)
102+mapExceptT t f m = tagged t $ Trans.mapExceptT f (coerce m)
105
103
106throw :: Monad m => proxy tag -> e -> ExceptT tag e m a
104throw :: Monad m => proxy tag -> e -> ExceptT tag e m a
107−throw t = tagWrap t . Trans.throwE
105+throw t = tagged t . Trans.throwE
108
106
109catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
107catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
110−catch t m h = tagWrap t $ Trans.catchE (coerce m) (coerce . h)
108+catch t m h = tagged t $ Trans.catchE (coerce m) (coerce . h)
111
109
112-- | Lift a @callCC@ operation to the new monad.
110-- | Lift a @callCC@ operation to the new monad.
113liftCallCC :: proxy tag -> Sig.CallCC m (Either e a) (Either e b) -> Sig.CallCC (ExceptT tag e m) a b
111liftCallCC :: proxy tag -> Sig.CallCC m (Either e a) (Either e b) -> Sig.CallCC (ExceptT tag e m) a b
114−liftCallCC t callCC f = tagWrap t $ Trans.liftCallCC callCC (coerce f)
112+liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
115
113
116-- | Lift a @listen@ operation to the new monad.
114-- | Lift a @listen@ operation to the new monad.
117liftListen :: Monad m => proxy tag -> Sig.Listen w m (Either e a) -> Sig.Listen w (ExceptT tag e m) a
115liftListen :: Monad m => proxy tag -> Sig.Listen w m (Either e a) -> Sig.Listen w (ExceptT tag e m) a
118−liftListen t listen m = tagWrap t $ Trans.liftListen listen (coerce m)
116+liftListen t listen m = tagged t $ Trans.liftListen listen (coerce m)
119
117
120-- | Lift a @pass@ operation to the new monad.
118-- | Lift a @pass@ operation to the new monad.
121liftPass :: Monad m => proxy tag -> Sig.Pass w m (Either e a) -> Sig.Pass w (ExceptT tag e m) a
119liftPass :: Monad m => proxy tag -> Sig.Pass w m (Either e a) -> Sig.Pass w (ExceptT tag e m) a
122−liftPass t pass m = tagWrap t $ Trans.liftPass pass (coerce m)
120+liftPass t pass m = tagged t $ Trans.liftPass pass (coerce m)
123
121
124-- | Lift a @catchE@ operation to the new monad.
122-- | Lift a @catchE@ operation to the new monad.
125liftCatch :: proxy tag -> Sig.Catch e m (Either e' a) -> Sig.Catch e (ExceptT tag e' m) a
123liftCatch :: proxy tag -> Sig.Catch e m (Either e' a) -> Sig.Catch e (ExceptT tag e' m) a
126−liftCatch t catchE m h = tagWrap t $ Util.liftCatch_ExceptT catchE (coerce m) (coerce h)
124+liftCatch t catchE m h = tagged t $ Util.liftCatch_ExceptT catchE (coerce m) (coerce h)
127
125
128instance Class.MonadCont m => Class.MonadCont (ExceptT tag e m) where
126instance Class.MonadCont m => Class.MonadCont (ExceptT tag e m) where
129 callCC = liftCallCC Proxy Class.callCC
127 callCC = liftCallCC Proxy Class.callCC
src/Control/Monad/Trans/Ether/Reader.hs+17−19
@@ -24,9 +24,6 @@ module Control.Monad.Trans.Ether.Reader
24 -- * Lifting other operations
24 -- * Lifting other operations
25 , liftCatch
25 , liftCatch
26 , liftCallCC
26 , liftCallCC
27− -- * Wrapping operations
28− , tagWrap
29− , tagUnwrap
30 ) where
27 ) where
31
28
32import Data.Proxy (Proxy(Proxy))
29import Data.Proxy (Proxy(Proxy))
@@ -37,7 +34,7 @@ import Control.Monad (MonadPlus)
37import Control.Monad.Fix (MonadFix)
34import Control.Monad.Fix (MonadFix)
38import Control.Monad.Trans.Class (MonadTrans, lift)
35import Control.Monad.Trans.Class (MonadTrans, lift)
39import Control.Monad.IO.Class (MonadIO)
36import Control.Monad.IO.Class (MonadIO)
40−import Control.Ether.Tags (Tags)
37+import Control.Ether.Tags (Taggable(..), Tagged(..), Tags)
41
38
42import qualified Control.Monad.Signatures as Sig
39import qualified Control.Monad.Signatures as Sig
43import qualified Control.Monad.Trans.Reader as Trans
40import qualified Control.Monad.Trans.Reader as Trans
@@ -65,38 +62,39 @@ newtype ReaderT tag r m a = ReaderT (Trans.ReaderT r m a)
65 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
62 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
66 , MonadFix, MonadTrans, MonadIO )
63 , MonadFix, MonadTrans, MonadIO )
67
64
68−tagWrap :: proxy tag -> Trans.ReaderT r m a -> ReaderT tag r m a
65+instance Taggable (ReaderT tag r m) where
69−tagWrap _ = ReaderT
66+ type Tag (ReaderT tag r m) = 'Just tag
67+ type Tags' (ReaderT tag r m) = Tags m
70
68
69+instance Tagged (ReaderT tag r m) tag where
71−tagUnwrap :: proxy tag -> ReaderT tag r m a -> Trans.ReaderT r m a
70+ type Untagged (ReaderT tag r m) = Trans.ReaderT r m
72−tagUnwrap _ (ReaderT a) = a
71+ tagged _ = ReaderT
73−
72+ untagged _ (ReaderT a) = a
74−type instance Tags (ReaderT tag r m) = tag ': Tags m
75
73
76-- | Constructor for computations in the reader monad transformer.
74-- | Constructor for computations in the reader monad transformer.
77readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a
75readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a
78−readerT t = tagWrap t . Trans.ReaderT
76+readerT t = tagged t . Trans.ReaderT
79
77
80-- | Constructor for computations in the reader monad
78-- | Constructor for computations in the reader monad
81-- (the inverse of 'runReader').
79-- (the inverse of 'runReader').
82reader :: Monad m => proxy tag -> (r -> a) -> ReaderT tag r m a
80reader :: Monad m => proxy tag -> (r -> a) -> ReaderT tag r m a
83−reader t = tagWrap t . Trans.reader
81+reader t = tagged t . Trans.reader
84
82
85-- | Runs a 'ReaderT' with the given environment
83-- | Runs a 'ReaderT' with the given environment
86-- and returns the vinal value.
84-- and returns the vinal value.
87runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a
85runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a
88−runReaderT t = Trans.runReaderT . tagUnwrap t
86+runReaderT t = Trans.runReaderT . untagged t
89
87
90-- | Runs a 'ReaderT' with the given environment
88-- | Runs a 'ReaderT' with the given environment
91-- and returns the vinal value.
89-- and returns the vinal value.
92runReader :: proxy tag -> Reader tag r a -> r -> a
90runReader :: proxy tag -> Reader tag r a -> r -> a
93−runReader t = Trans.runReader . tagUnwrap t
91+runReader t = Trans.runReader . untagged t
94
92
95-- | Transform the computation inside a 'ReaderT'.
93-- | Transform the computation inside a 'ReaderT'.
96--
94--
97-- * @'runReaderT' tag ('mapReaderT' tag f m) = f . 'runReaderT' tag m@
95-- * @'runReaderT' tag ('mapReaderT' tag f m) = f . 'runReaderT' tag m@
98mapReaderT :: proxy tag -> (m a -> n b) -> ReaderT tag r m a -> ReaderT tag r n b
96mapReaderT :: proxy tag -> (m a -> n b) -> ReaderT tag r m a -> ReaderT tag r n b
99−mapReaderT t f m = tagWrap t $ Trans.mapReaderT f (coerce m)
97+mapReaderT t f m = tagged t $ Trans.mapReaderT f (coerce m)
100
98
101-- | Execute a computation in a modified environment
99-- | Execute a computation in a modified environment
102-- (a more general version of 'local').
100-- (a more general version of 'local').
@@ -109,19 +107,19 @@ withReaderT
109 -> ReaderT tag r m a
107 -> ReaderT tag r m a
110 -- ^ Computation to run in the modified environment.
108 -- ^ Computation to run in the modified environment.
111 -> ReaderT tag r' m a
109 -> ReaderT tag r' m a
112−withReaderT t f m = tagWrap t $ Trans.withReaderT f (coerce m)
110+withReaderT t f m = tagged t $ Trans.withReaderT f (coerce m)
113
111
114-- | Lift a @catchE@ operation to the new monad.
112-- | Lift a @catchE@ operation to the new monad.
115liftCatch :: proxy tag -> Sig.Catch e m a -> Sig.Catch e (ReaderT tag r m) a
113liftCatch :: proxy tag -> Sig.Catch e m a -> Sig.Catch e (ReaderT tag r m) a
116−liftCatch t f m h = tagWrap t $ Trans.liftCatch f (coerce m) (coerce h)
114+liftCatch t f m h = tagged t $ Trans.liftCatch f (coerce m) (coerce h)
117
115
118-- | Lift a @callCC@ operation to the new monad.
116-- | Lift a @callCC@ operation to the new monad.
119liftCallCC :: proxy tag -> Sig.CallCC m a b -> Sig.CallCC (ReaderT tag r m) a b
117liftCallCC :: proxy tag -> Sig.CallCC m a b -> Sig.CallCC (ReaderT tag r m) a b
120−liftCallCC t callCC f = tagWrap t $ Trans.liftCallCC callCC (coerce f)
118+liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
121
119
122-- | Fetch the value of the environment.
120-- | Fetch the value of the environment.
123ask :: Monad m => proxy tag -> ReaderT tag r m r
121ask :: Monad m => proxy tag -> ReaderT tag r m r
124−ask t = tagWrap t Trans.ask
122+ask t = tagged t Trans.ask
125
123
126-- | Execute a computation in a modified environment
124-- | Execute a computation in a modified environment
127-- (a specialization of 'withReaderT').
125-- (a specialization of 'withReaderT').
src/Control/Monad/Trans/Ether/State.hs+23−24
@@ -29,9 +29,6 @@ module Control.Monad.Trans.Ether.State
29 , liftCallCC'
29 , liftCallCC'
30 , liftListen
30 , liftListen
31 , liftPass
31 , liftPass
32− -- * Wrapping operations
33− , tagWrap
34− , tagUnwrap
35 ) where
32 ) where
36
33
37import Data.Proxy (Proxy(Proxy))
34import Data.Proxy (Proxy(Proxy))
@@ -42,7 +39,7 @@ import Control.Monad (MonadPlus)
42import Control.Monad.Fix (MonadFix)
39import Control.Monad.Fix (MonadFix)
43import Control.Monad.Trans.Class (MonadTrans, lift)
40import Control.Monad.Trans.Class (MonadTrans, lift)
44import Control.Monad.IO.Class (MonadIO)
41import Control.Monad.IO.Class (MonadIO)
45−import Control.Ether.Tags (Tags)
42+import Control.Ether.Tags (Taggable(..), Tagged(..), Tags)
46
43
47import qualified Control.Monad.Signatures as Sig
44import qualified Control.Monad.Signatures as Sig
48import qualified Control.Monad.Trans.State.Lazy as Trans
45import qualified Control.Monad.Trans.State.Lazy as Trans
@@ -72,84 +69,86 @@ newtype StateT tag s m a = StateT (Trans.StateT s m a)
72 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
69 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
73 , MonadFix, MonadTrans, MonadIO )
70 , MonadFix, MonadTrans, MonadIO )
74
71
75−type instance Tags (StateT tag r m) = tag ': Tags m
76
72
77−tagWrap :: proxy tag -> Trans.StateT s m a -> StateT tag s m a
73+instance Taggable (StateT tag s m) where
78−tagWrap _ = StateT
74+ type Tag (StateT tag s m) = 'Just tag
75+ type Tags' (StateT tag s m) = Tags m
79
76
77+instance Tagged (StateT tag s m) tag where
80−tagUnwrap :: proxy tag -> StateT tag s m a -> Trans.StateT s m a
78+ type Untagged (StateT tag s m) = Trans.StateT s m
79+ tagged _ = StateT
81−tagUnwrap _ (StateT a) = a
80+ untagged _ (StateT a) = a
82
81
83-- | Constructor for computations in the state monad transformer.
82-- | Constructor for computations in the state monad transformer.
84stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a
83stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a
85−stateT t = tagWrap t . Trans.StateT
84+stateT t = tagged t . Trans.StateT
86
85
87-- | Constructor for computations in the state monad
86-- | Constructor for computations in the state monad
88-- (the inverse of 'runState').
87-- (the inverse of 'runState').
89state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a
88state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a
90−state t = tagWrap t . Trans.state
89+state t = tagged t . Trans.state
91
90
92-- | Runs a 'StateT' with the given initial state
91-- | Runs a 'StateT' with the given initial state
93-- and returns both the final value and the final state.
92-- and returns both the final value and the final state.
94runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s)
93runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s)
95−runStateT t = Trans.runStateT . tagUnwrap t
94+runStateT t = Trans.runStateT . untagged t
96
95
97-- | Runs a 'StateT' with the given initial state
96-- | Runs a 'StateT' with the given initial state
98-- and returns the final value, discarding the final state.
97-- and returns the final value, discarding the final state.
99evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a
98evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a
100−evalStateT t = Trans.evalStateT . tagUnwrap t
99+evalStateT t = Trans.evalStateT . untagged t
101
100
102-- | Runs a 'StateT' with the given initial state
101-- | Runs a 'StateT' with the given initial state
103-- and returns the final state, discarding the final value.
102-- and returns the final state, discarding the final value.
104execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s
103execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s
105−execStateT t = Trans.execStateT . tagUnwrap t
104+execStateT t = Trans.execStateT . untagged t
106
105
107-- | Runs a 'State' with the given initial state
106-- | Runs a 'State' with the given initial state
108-- and returns both the final value and the final state.
107-- and returns both the final value and the final state.
109runState :: proxy tag -> State tag s a -> s -> (a, s)
108runState :: proxy tag -> State tag s a -> s -> (a, s)
110−runState t = Trans.runState . tagUnwrap t
109+runState t = Trans.runState . untagged t
111
110
112-- | Runs a 'State' with the given initial state
111-- | Runs a 'State' with the given initial state
113-- and returns the final value, discarding the final state.
112-- and returns the final value, discarding the final state.
114evalState :: proxy tag -> State tag s a -> s -> a
113evalState :: proxy tag -> State tag s a -> s -> a
115−evalState t = Trans.evalState . tagUnwrap t
114+evalState t = Trans.evalState . untagged t
116
115
117-- | Runs a 'State' with the given initial state
116-- | Runs a 'State' with the given initial state
118-- and returns the final state, discarding the final value.
117-- and returns the final state, discarding the final value.
119execState :: proxy tag -> State tag s a -> s -> s
118execState :: proxy tag -> State tag s a -> s -> s
120−execState t = Trans.execState . tagUnwrap t
119+execState t = Trans.execState . untagged t
121
120
122-- | Transform the computation inside a 'StateT'.
121-- | Transform the computation inside a 'StateT'.
123--
122--
124-- * @'runStateT' tag ('mapStateT' tag f m) = f . 'runStateT' tag m@
123-- * @'runStateT' tag ('mapStateT' tag f m) = f . 'runStateT' tag m@
125mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b
124mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b
126−mapStateT t f m = tagWrap t $ Trans.mapStateT f (coerce m)
125+mapStateT t f m = tagged t $ Trans.mapStateT f (coerce m)
127
126
128-- | Fetch the current value of the state within the monad.
127-- | Fetch the current value of the state within the monad.
129get :: Monad m => proxy tag -> StateT tag s m s
128get :: Monad m => proxy tag -> StateT tag s m s
130−get t = tagWrap t Trans.get
129+get t = tagged t Trans.get
131
130
132-- | Set the value of the state within the monad.
131-- | Set the value of the state within the monad.
133put :: Monad m => proxy tag -> s -> StateT tag s m ()
132put :: Monad m => proxy tag -> s -> StateT tag s m ()
134−put t = tagWrap t . Trans.put
133+put t = tagged t . Trans.put
135
134
136-- | Lift a @catchE@ operation to the new monad.
135-- | Lift a @catchE@ operation to the new monad.
137liftCatch :: proxy tag -> Sig.Catch e m (a, s) -> Sig.Catch e (StateT tag s m) a
136liftCatch :: proxy tag -> Sig.Catch e m (a, s) -> Sig.Catch e (StateT tag s m) a
138−liftCatch t f m h = tagWrap t $ Trans.liftCatch f (coerce m) (coerce h)
137+liftCatch t f m h = tagged t $ Trans.liftCatch f (coerce m) (coerce h)
139
138
140-- | Lift a @listen@ operation to the new monad.
139-- | Lift a @listen@ operation to the new monad.
141liftListen :: Monad m => proxy tag -> Sig.Listen w m (a, s) -> Sig.Listen w (StateT tag s m) a
140liftListen :: Monad m => proxy tag -> Sig.Listen w m (a, s) -> Sig.Listen w (StateT tag s m) a
142−liftListen t listen m = tagWrap t $ Trans.liftListen listen (coerce m)
141+liftListen t listen m = tagged t $ Trans.liftListen listen (coerce m)
143
142
144-- | In-situ lifting of a @callCC@ operation to the new monad.
143-- | In-situ lifting of a @callCC@ operation to the new monad.
145-- This version uses the current state on entering the continuation.
144-- This version uses the current state on entering the continuation.
146-- It does not satisfy the uniformity property (see "Control.Monad.Signatures").
145-- It does not satisfy the uniformity property (see "Control.Monad.Signatures").
147liftCallCC' :: proxy tag -> Sig.CallCC m (a, s) (b, s) -> Sig.CallCC (StateT tag s m) a b
146liftCallCC' :: proxy tag -> Sig.CallCC m (a, s) (b, s) -> Sig.CallCC (StateT tag s m) a b
148−liftCallCC' t callCC f = tagWrap t $ Trans.liftCallCC' callCC (coerce f)
147+liftCallCC' t callCC f = tagged t $ Trans.liftCallCC' callCC (coerce f)
149
148
150-- | Lift a @pass@ operation to the new monad.
149-- | Lift a @pass@ operation to the new monad.
151liftPass :: Monad m => proxy tag -> Sig.Pass w m (a,s) -> Sig.Pass w (StateT tag s m) a
150liftPass :: Monad m => proxy tag -> Sig.Pass w m (a,s) -> Sig.Pass w (StateT tag s m) a
152−liftPass t pass m = tagWrap t $ Trans.liftPass pass (coerce m)
151+liftPass t pass m = tagged t $ Trans.liftPass pass (coerce m)
153
152
154-- Instances for mtl classes
153-- Instances for mtl classes
155
154