on master help sign in
Merge pull request #10 from int-index/tt

Unified tagging wrapper

commit6f616b3feac3ca8cc497a56c93c38db16d0d6bde authorIndex Int <vlad.z.4096@gmail.com> dateTue 26 Jan 2016, 17:54 (11 years ago) parentda52dc70bcecdd
12 files changed+226−502
.travis.yml+16−15 ether.cabal+1−1 src/Control/Ether/TT.hs+174 src/Control/Ether/Util.hs+13−2 src/Control/Monad/Trans/Ether/Except.hs+2−95 src/Control/Monad/Trans/Ether/Reader.hs+2−97 src/Control/Monad/Trans/Ether/State/Lazy.hs+2−98 src/Control/Monad/Trans/Ether/State/Strict.hs+2−98 src/Control/Monad/Trans/Ether/Writer.hs+2−95 stack.yaml+1−1 travis/shc.sh+4 travis/test.sh+7
.travis.yml+16−15
@@ -1,26 +1,29 @@
11sudo: false
22
33env:
4− - CABALVER=1.18 GHCVER=7.8.4
5− - CABALVER=1.22 GHCVER=7.10.3
4+ - GHCVER=7.8.4 STACK_YAML=stack-ghc-7.8.4.yaml
5+ - GHCVER=7.10.3 STACK_YAML=stack.yaml COVERAGE="YES"
6+
7+cache:
8+ directories:
9+ - $HOME/.stack/
610
711before_install:
8− - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$HOME/.cabal/bin:$PATH
9− - travis_retry cabal update
12+ - export PATH=/opt/ghc/$GHCVER/bin:$PATH
13+ - mkdir -p ~/.local/bin
14+ - travis_retry curl -L https://github.com/commercialhaskell/stack/releases/download/v1.0.2/stack-1.0.2-linux-x86_64.tar.gz | tar -xvz
15+ - mv stack-1.0.2-linux-x86_64/stack ~/.local/bin
16+ - export PATH=~/.local/bin:$PATH
17+ - stack --version
1018
1119install:
12− - cabal --version
13− - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
14− - cabal install --only-dependencies --enable-tests
20+ - stack install --only-dependencies --no-terminal
1521
1622script:
17− - cabal configure --enable-tests --enable-library-coverage -v2
18− - cabal build
19− - cabal test
23+ - travis/test.sh
2024
2125after_script:
22− - cabal install hpc-coveralls
23− - hpc-coveralls regression --exclude-dir=test
26+ - travis/shc.sh
2427
2528addons:
2629 apt:
@@ -28,6 +31,4 @@ addons:
2831 - hvr-ghc
2932 packages:
3033 - ghc-7.8.4
31− - ghc-7.10.3
32− - cabal-install-1.18
33− - cabal-install-1.22
34+ - ghc-7.10.3
ether.cabal+1−1
@@ -27,6 +27,7 @@ library
2727 exposed-modules: Control.Ether.Abbr
2828 Control.Ether.Implicit.Abbr
2929 Control.Ether.TH
30+ Control.Ether.TT
3031 Control.Monad.Trans.Ether.Reader
3132 Control.Monad.Trans.Ether.Writer
3233 Control.Monad.Trans.Ether.State
@@ -75,7 +76,6 @@ library
7576 FunctionalDependencies
7677 GeneralizedNewtypeDeriving
7778 MultiParamTypeClasses
78− PolyKinds
7979 ScopedTypeVariables
8080 TemplateHaskell
8181 TypeFamilies
src/Control/Ether/TT.hsnew file+174
@@ -0,0 +1,174 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE PolyKinds #-}
5+{-# LANGUAGE MultiParamTypeClasses #-}
6+{-# LANGUAGE UndecidableInstances #-}
7+{-# LANGUAGE ConstraintKinds #-}
8+{-# LANGUAGE TypeFamilies #-}
9+module Control.Ether.TT where
10+
11+import Control.Applicative
12+import Control.Monad (MonadPlus)
13+import Control.Monad.Fix (MonadFix)
14+import Control.Monad.Trans.Class (MonadTrans, lift)
15+import Control.Monad.IO.Class (MonadIO)
16+import Control.Monad.Morph (MFunctor, MMonad)
17+import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
18+
19+import qualified Control.Monad.Base as MB
20+import qualified Control.Monad.Trans.Control as MC
21+
22+import qualified Control.Monad.Trans.Lift.StT as Lift
23+import qualified Control.Monad.Trans.Lift.Local as Lift
24+import qualified Control.Monad.Trans.Lift.Catch as Lift
25+import qualified Control.Monad.Trans.Lift.Listen as Lift
26+import qualified Control.Monad.Trans.Lift.Pass as Lift
27+import qualified Control.Monad.Trans.Lift.CallCC as Lift
28+
29+import qualified Control.Monad.Cont.Class as Class
30+import qualified Control.Monad.Reader.Class as Class
31+import qualified Control.Monad.State.Class as Class
32+import qualified Control.Monad.Writer.Class as Class
33+import qualified Control.Monad.Error.Class as Class
34+
35+import GHC.Generics (Generic)
36+import Data.Coerce (coerce)
37+
38+import Control.Ether.Util (MonadApplicative)
39+
40+-- | Tagged monad transformer.
41+newtype TT tag trans (m :: * -> *) a = TT (trans m a)
42+ deriving
43+ ( Generic
44+ , Functor
45+ , Applicative
46+ , Alternative
47+ , Monad
48+ , MonadPlus
49+ , MonadFix
50+ , MonadTrans
51+ , MonadIO
52+ , MFunctor
53+ , MMonad
54+ , MonadThrow
55+ , MonadCatch
56+ , MonadMask )
57+
58+-- | Type-restricted 'coerce'.
59+pack :: trans m a -> TT tag trans m a
60+pack = coerce
61+
62+-- | Type-restricted 'coerce'.
63+unpack :: TT tag trans m a -> trans m a
64+unpack = coerce
65+
66+instance
67+ ( MB.MonadBase b m
68+ , MonadTrans trans
69+ , MonadApplicative (trans m)
70+ ) => MB.MonadBase b (TT tag trans m)
71+ where
72+ liftBase = MB.liftBaseDefault
73+
74+instance
75+ ( MC.MonadTransControl trans
76+ ) => MC.MonadTransControl (TT tag trans)
77+ where
78+ type StT (TT tag trans) a = MC.StT trans a
79+ liftWith = MC.defaultLiftWith pack unpack
80+ restoreT = MC.defaultRestoreT pack
81+
82+instance
83+ ( MC.MonadBaseControl b m
84+ , MC.MonadTransControl trans
85+ , MonadApplicative (trans m)
86+ ) => MC.MonadBaseControl b (TT tag trans m)
87+ where
88+ type StM (TT tag trans m) a = MC.ComposeSt trans m a
89+ liftBaseWith = MC.defaultLiftBaseWith
90+ restoreM = MC.defaultRestoreM
91+
92+type instance Lift.StT (TT tag trans) a = Lift.StT trans a
93+
94+instance
95+ ( Lift.LiftLocal trans
96+ ) => Lift.LiftLocal (TT tag trans)
97+ where
98+ liftLocal = Lift.defaultLiftLocal pack unpack
99+
100+instance
101+ ( Lift.LiftCatch trans
102+ ) => Lift.LiftCatch (TT tag trans)
103+ where
104+ liftCatch = Lift.defaultLiftCatch pack unpack
105+
106+instance
107+ ( Lift.LiftListen trans
108+ ) => Lift.LiftListen (TT tag trans)
109+ where
110+ liftListen = Lift.defaultLiftListen pack unpack
111+
112+instance
113+ ( Lift.LiftPass trans
114+ ) => Lift.LiftPass (TT tag trans)
115+ where
116+ liftPass = Lift.defaultLiftPass pack unpack
117+
118+instance
119+ ( Lift.LiftCallCC trans
120+ ) => Lift.LiftCallCC (TT tag trans)
121+ where
122+ liftCallCC = Lift.defaultLiftCallCC pack unpack
123+ liftCallCC' = Lift.defaultLiftCallCC' pack unpack
124+
125+-- Instances for mtl classes
126+
127+instance
128+ ( Class.MonadCont m
129+ , Lift.LiftCallCC trans
130+ , Monad (trans m)
131+ ) => Class.MonadCont (TT tag trans m)
132+ where
133+ callCC = Lift.liftCallCC' Class.callCC
134+
135+instance
136+ ( Class.MonadReader r m
137+ , Lift.LiftLocal trans
138+ , Monad (trans m)
139+ ) => Class.MonadReader r (TT tag trans m)
140+ where
141+ ask = lift Class.ask
142+ local = Lift.liftLocal Class.ask Class.local
143+ reader = lift . Class.reader
144+
145+instance
146+ ( Class.MonadState s m
147+ , MonadTrans trans
148+ , Monad (trans m)
149+ ) => Class.MonadState s (TT tag trans m)
150+ where
151+ get = lift Class.get
152+ put = lift . Class.put
153+ state = lift . Class.state
154+
155+instance
156+ ( Class.MonadWriter w m
157+ , Lift.LiftListen trans
158+ , Lift.LiftPass trans
159+ , Monad (trans m)
160+ ) => Class.MonadWriter w (TT tag trans m)
161+ where
162+ writer = lift . Class.writer
163+ tell = lift . Class.tell
164+ listen = Lift.liftListen Class.listen
165+ pass = Lift.liftPass Class.pass
166+
167+instance
168+ ( Class.MonadError e m
169+ , Lift.LiftCatch trans
170+ , Monad (trans m)
171+ ) => Class.MonadError e (TT tag trans m)
172+ where
173+ throwError = lift . Class.throwError
174+ catchError = Lift.liftCatch Class.catchError
src/Control/Ether/Util.hs+13−2
@@ -1,11 +1,14 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ConstraintKinds #-}
23module Control.Ether.Util
3− ( fmap
4− ) where
4+ ( fmap
5+ , MonadApplicative
6+ ) where
57
68import Prelude hiding (fmap)
79
810#if __GLASGOW_HASKELL__ < 710
11+import qualified Control.Applicative
912import qualified Control.Monad
1013#else
1114import qualified Prelude
@@ -20,3 +23,11 @@ fmap = Prelude.fmap
2023#endif
2124
2225{-# INLINE fmap #-}
26+
27+#if __GLASGOW_HASKELL__ < 710
28+type MonadApplicative m =
29+ ( Control.Applicative.Applicative m
30+ , Control.Monad.Monad m )
31+#else
32+type MonadApplicative = Monad
33+#endif
src/Control/Monad/Trans/Ether/Except.hs+2−95
@@ -22,38 +22,11 @@ module Control.Monad.Trans.Ether.Except
2222 -- * Exception operations
2323 , throw
2424 , catch
25− -- * Newtype operations
26− , pack
27− , unpack
2825 ) where
2926
3027import Data.Functor.Identity (Identity(..))
31−import Control.Applicative
32−import Control.Monad (MonadPlus)
33−import Control.Monad.Fix (MonadFix)
34−import Control.Monad.Trans.Class (MonadTrans, lift)
35−import Control.Monad.IO.Class (MonadIO)
36−import Control.Monad.Morph (MFunctor, MMonad)
37−import Control.Monad.Catch (MonadThrow, MonadCatch)
38−import GHC.Generics (Generic)
39−import Data.Coerce (coerce)
40−
41−import qualified Control.Monad.Base as MB
42−import qualified Control.Monad.Trans.Control as MC
4328import qualified Control.Monad.Trans.Except as Trans
44−
45−import qualified Control.Monad.Trans.Lift.StT as Lift
46−import qualified Control.Monad.Trans.Lift.Local as Lift
47−import qualified Control.Monad.Trans.Lift.Catch as Lift
48−import qualified Control.Monad.Trans.Lift.Listen as Lift
49−import qualified Control.Monad.Trans.Lift.Pass as Lift
50−import qualified Control.Monad.Trans.Lift.CallCC as Lift
51−
52−import qualified Control.Monad.Cont.Class as Class
53−import qualified Control.Monad.Reader.Class as Class
54−import qualified Control.Monad.State.Class as Class
55−import qualified Control.Monad.Writer.Class as Class
56−import qualified Control.Monad.Error.Class as Class
29+import Control.Ether.TT
5730
5831
5932-- | The parameterizable exception monad.
@@ -72,50 +45,7 @@ runExcept t = Trans.runExcept . untagged t
7245--
7346-- The 'return' function returns a normal value, while '>>=' exits on
7447-- the first exception.
75−newtype ExceptT tag e m a = ExceptT (Trans.ExceptT e m a)
76− deriving ( Generic
77− , Functor, Applicative, Alternative, Monad, MonadPlus
78− , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
79− , MonadThrow, MonadCatch )
80−
81−-- | Type-restricted 'coerce'.
82−pack :: Trans.ExceptT e m a -> ExceptT tag e m a
83−pack = coerce
84−
85−-- | Type-restricted 'coerce'.
86−unpack :: ExceptT tag e m a -> Trans.ExceptT e m a
87−unpack = coerce
88−
89−instance MB.MonadBase b m => MB.MonadBase b (ExceptT tag e m) where
90− liftBase = MB.liftBaseDefault
91−
92−instance MC.MonadTransControl (ExceptT tag e) where
93− type StT (ExceptT tag e) a = MC.StT (Trans.ExceptT e) a
94− liftWith = MC.defaultLiftWith pack unpack
95− restoreT = MC.defaultRestoreT pack
96−
97−instance MC.MonadBaseControl b m => MC.MonadBaseControl b (ExceptT tag e m) where
98− type StM (ExceptT tag e m) a = MC.ComposeSt (ExceptT tag e) m a
99− liftBaseWith = MC.defaultLiftBaseWith
100− restoreM = MC.defaultRestoreM
101−
102−type instance Lift.StT (ExceptT tag e) a = MC.StT (ExceptT tag e) a
103−
104−instance Lift.LiftLocal (ExceptT tag e) where
105− liftLocal = Lift.defaultLiftLocal pack unpack
106−
107−instance Lift.LiftCatch (ExceptT tag e) where
108− liftCatch = Lift.defaultLiftCatch pack unpack
109−
110−instance Lift.LiftListen (ExceptT tag e) where
111− liftListen = Lift.defaultLiftListen pack unpack
112−
113−instance Lift.LiftPass (ExceptT tag e) where
114− liftPass = Lift.defaultLiftPass pack unpack
115−
116−instance Lift.LiftCallCC (ExceptT tag e) where
117− liftCallCC = Lift.defaultLiftCallCC pack unpack
118− liftCallCC' = Lift.defaultLiftCallCC pack unpack
48+type ExceptT tag e = TT tag (Trans.ExceptT e)
11949
12050tagged :: proxy tag -> Trans.ExceptT e m a -> ExceptT tag e m a
12151tagged _ = pack
@@ -143,26 +73,3 @@ throw t = tagged t . Trans.throwE
14373-- | A handler function to handle previous exceptions and return to normal execution.
14474catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
14575catch t m h = tagged t $ Trans.catchE (untagged t m) (untagged t . h)
146−
147−instance Class.MonadCont m => Class.MonadCont (ExceptT tag e m) where
148− callCC = Lift.liftCallCC Class.callCC
149−
150−instance Class.MonadReader r m => Class.MonadReader r (ExceptT tag e m) where
151− ask = lift Class.ask
152− local = Lift.liftLocal Class.ask Class.local
153− reader = lift . Class.reader
154−
155−instance Class.MonadState s m => Class.MonadState s (ExceptT tag e m) where
156− get = lift Class.get
157− put = lift . Class.put
158− state = lift . Class.state
159−
160−instance Class.MonadWriter w m => Class.MonadWriter w (ExceptT tag e m) where
161− writer = lift . Class.writer
162− tell = lift . Class.tell
163− listen = Lift.liftListen Class.listen
164− pass = Lift.liftPass Class.pass
165−
166−instance Class.MonadError e' m => Class.MonadError e' (ExceptT tag e m) where
167− throwError = lift . Class.throwError
168− catchError = Lift.liftCatch Class.catchError
src/Control/Monad/Trans/Ether/Reader.hs+2−97
@@ -22,38 +22,11 @@ module Control.Monad.Trans.Ether.Reader
2222 -- * Reader operations
2323 , ask
2424 , local
25− -- * Newtype operations
26− , pack
27− , unpack
2825 ) where
2926
3027import Data.Functor.Identity (Identity(..))
31−import Control.Applicative
32−import Control.Monad (MonadPlus)
33−import Control.Monad.Fix (MonadFix)
34−import Control.Monad.Trans.Class (MonadTrans, lift)
35−import Control.Monad.IO.Class (MonadIO)
36−import Control.Monad.Morph (MFunctor, MMonad)
37−import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
38−import GHC.Generics (Generic)
39−import Data.Coerce (coerce)
40−
41−import qualified Control.Monad.Base as MB
42−import qualified Control.Monad.Trans.Control as MC
4328import qualified Control.Monad.Trans.Reader as Trans
44−
45−import qualified Control.Monad.Trans.Lift.StT as Lift
46−import qualified Control.Monad.Trans.Lift.Local as Lift
47−import qualified Control.Monad.Trans.Lift.Catch as Lift
48−import qualified Control.Monad.Trans.Lift.Listen as Lift
49−import qualified Control.Monad.Trans.Lift.Pass as Lift
50−import qualified Control.Monad.Trans.Lift.CallCC as Lift
51−
52−import qualified Control.Monad.Cont.Class as Class
53−import qualified Control.Monad.Reader.Class as Class
54−import qualified Control.Monad.State.Class as Class
55−import qualified Control.Monad.Writer.Class as Class
56−import qualified Control.Monad.Error.Class as Class
29+import Control.Ether.TT
5730
5831-- | The parameterizable reader monad.
5932--
@@ -68,50 +41,7 @@ type Reader tag r = ReaderT tag r Identity
6841--
6942-- The 'return' function ignores the environment, while '>>=' passes
7043-- the inherited environment to both subcomputations.
71−newtype ReaderT tag r m a = ReaderT (Trans.ReaderT r m a)
72− deriving ( Generic
73− , Functor, Applicative, Alternative, Monad, MonadPlus
74− , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
75− , MonadThrow, MonadCatch, MonadMask )
76−
77−-- | Type-restricted 'coerce'.
78−pack :: Trans.ReaderT r m a -> ReaderT tag r m a
79−pack = coerce
80−
81−-- | Type-restricted 'coerce'.
82−unpack :: ReaderT tag r m a -> Trans.ReaderT r m a
83−unpack = coerce
84−
85−instance MB.MonadBase b m => MB.MonadBase b (ReaderT tag r m) where
86− liftBase = MB.liftBaseDefault
87−
88−instance MC.MonadTransControl (ReaderT tag r) where
89− type StT (ReaderT tag r) a = MC.StT (Trans.ReaderT r) a
90− liftWith = MC.defaultLiftWith pack unpack
91− restoreT = MC.defaultRestoreT pack
92−
93−instance MC.MonadBaseControl b m => MC.MonadBaseControl b (ReaderT tag r m) where
94− type StM (ReaderT tag r m) a = MC.ComposeSt (ReaderT tag r) m a
95− liftBaseWith = MC.defaultLiftBaseWith
96− restoreM = MC.defaultRestoreM
97−
98−type instance Lift.StT (ReaderT tag r) a = MC.StT (ReaderT tag r) a
99−
100−instance Lift.LiftLocal (ReaderT tag r) where
101− liftLocal = Lift.defaultLiftLocal pack unpack
102−
103−instance Lift.LiftCatch (ReaderT tag r) where
104− liftCatch = Lift.defaultLiftCatch pack unpack
105−
106−instance Lift.LiftListen (ReaderT tag r) where
107− liftListen = Lift.defaultLiftListen pack unpack
108−
109−instance Lift.LiftPass (ReaderT tag r) where
110− liftPass = Lift.defaultLiftPass pack unpack
111−
112−instance Lift.LiftCallCC (ReaderT tag r) where
113− liftCallCC = Lift.defaultLiftCallCC pack unpack
114− liftCallCC' = Lift.defaultLiftCallCC' pack unpack
44+type ReaderT tag r = TT tag (Trans.ReaderT r)
11545
11646tagged :: proxy tag -> Trans.ReaderT r m a -> ReaderT tag r m a
11747tagged _ = pack
@@ -154,28 +84,3 @@ local
15484 -- ^ Computation to run in the modified environment.
15585 -> ReaderT tag r m a
15686local t f m = tagged t $ Trans.withReaderT f (untagged t m)
157−
158−-- Instances for mtl classes
159−
160−instance Class.MonadCont m => Class.MonadCont (ReaderT tag r m) where
161− callCC = Lift.liftCallCC Class.callCC
162−
163−instance Class.MonadReader r' m => Class.MonadReader r' (ReaderT tag r m) where
164− ask = lift Class.ask
165− local = Lift.liftLocal Class.ask Class.local
166− reader = lift . Class.reader
167−
168−instance Class.MonadState s m => Class.MonadState s (ReaderT tag r m) where
169− get = lift Class.get
170− put = lift . Class.put
171− state = lift . Class.state
172−
173−instance Class.MonadWriter w m => Class.MonadWriter w (ReaderT tag r m) where
174− writer = lift . Class.writer
175− tell = lift . Class.tell
176− listen = Lift.liftListen Class.listen
177− pass = Lift.liftPass Class.pass
178−
179−instance Class.MonadError e m => Class.MonadError e (ReaderT tag r m) where
180− throwError = lift . Class.throwError
181− catchError = Lift.liftCatch Class.catchError
src/Control/Monad/Trans/Ether/State/Lazy.hs+2−98
@@ -26,39 +26,11 @@ module Control.Monad.Trans.Ether.State.Lazy
2626 -- * State operations
2727 , get
2828 , put
29− -- * Newtype operations
30− , pack
31− , unpack
3229 ) where
3330
3431import Data.Functor.Identity (Identity(..))
35−import Control.Applicative
36−import Control.Monad (MonadPlus)
37−import Control.Monad.Fix (MonadFix)
38−import Control.Monad.Trans.Class (MonadTrans, lift)
39−import Control.Monad.IO.Class (MonadIO)
40−import Control.Monad.Morph (MFunctor)
41−import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
42−import GHC.Generics (Generic)
43−import Data.Coerce (coerce)
44−
45−import qualified Control.Monad.Base as MB
46−import qualified Control.Monad.Trans.Control as MC
4732import qualified Control.Monad.Trans.State.Lazy as Trans
48−
49−import qualified Control.Monad.Trans.Lift.StT as Lift
50−import qualified Control.Monad.Trans.Lift.Local as Lift
51−import qualified Control.Monad.Trans.Lift.Catch as Lift
52−import qualified Control.Monad.Trans.Lift.Listen as Lift
53−import qualified Control.Monad.Trans.Lift.Pass as Lift
54−import qualified Control.Monad.Trans.Lift.CallCC as Lift
55−
56−import qualified Control.Monad.Cont.Class as Class
57−import qualified Control.Monad.Reader.Class as Class
58−import qualified Control.Monad.State.Class as Class
59−import qualified Control.Monad.Writer.Class as Class
60−import qualified Control.Monad.Error.Class as Class
61−
33+import Control.Ether.TT
6234
6335-- | The parametrizable state monad.
6436--
@@ -72,50 +44,7 @@ type State tag r = StateT tag r Identity
7244--
7345-- The 'return' function leaves the state unchanged, while '>>=' uses
7446-- the final state of the first computation as the initial state of the second.
75−newtype StateT tag s m a = StateT (Trans.StateT s m a)
76− deriving ( Generic
77− , Functor, Applicative, Alternative, Monad, MonadPlus
78− , MonadFix, MonadTrans, MonadIO, MFunctor
79− , MonadThrow, MonadCatch, MonadMask )
80−
81−-- | Type-restricted 'coerce'.
82−pack :: Trans.StateT s m a -> StateT tag s m a
83−pack = coerce
84−
85−-- | Type-restricted 'coerce'.
86−unpack :: StateT tag s m a -> Trans.StateT s m a
87−unpack = coerce
88−
89−instance MB.MonadBase b m => MB.MonadBase b (StateT tag s m) where
90− liftBase = MB.liftBaseDefault
91−
92−instance MC.MonadTransControl (StateT tag s) where
93− type StT (StateT tag s) a = MC.StT (Trans.StateT s) a
94− liftWith = MC.defaultLiftWith pack unpack
95− restoreT = MC.defaultRestoreT pack
96−
97−instance MC.MonadBaseControl b m => MC.MonadBaseControl b (StateT tag s m) where
98− type StM (StateT tag s m) a = MC.ComposeSt (StateT tag s) m a
99− liftBaseWith = MC.defaultLiftBaseWith
100− restoreM = MC.defaultRestoreM
101−
102−type instance Lift.StT (StateT tag s) a = MC.StT (StateT tag s) a
103−
104−instance Lift.LiftLocal (StateT tag s) where
105− liftLocal = Lift.defaultLiftLocal pack unpack
106−
107−instance Lift.LiftCatch (StateT tag s) where
108− liftCatch = Lift.defaultLiftCatch pack unpack
109−
110−instance Lift.LiftListen (StateT tag s) where
111− liftListen = Lift.defaultLiftListen pack unpack
112−
113−instance Lift.LiftPass (StateT tag s) where
114− liftPass = Lift.defaultLiftPass pack unpack
115−
116−instance Lift.LiftCallCC (StateT tag s) where
117− liftCallCC = Lift.defaultLiftCallCC pack unpack
118− liftCallCC' = Lift.defaultLiftCallCC' pack unpack
47+type StateT tag s = TT tag (Trans.StateT s)
11948
12049tagged :: proxy tag -> Trans.StateT s m a -> StateT tag s m a
12150tagged _ = pack
@@ -169,28 +98,3 @@ get t = tagged t Trans.get
16998-- | Set the value of the state within the monad.
17099put :: Monad m => proxy tag -> s -> StateT tag s m ()
171100put t = tagged t . Trans.put
172−
173−-- Instances for mtl classes
174−
175−instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
176− callCC = Lift.liftCallCC' Class.callCC
177−
178−instance Class.MonadReader r m => Class.MonadReader r (StateT tag s m) where
179− ask = lift Class.ask
180− local = Lift.liftLocal Class.ask Class.local
181− reader = lift . Class.reader
182−
183−instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
184− get = lift Class.get
185− put = lift . Class.put
186− state = lift . Class.state
187−
188−instance Class.MonadWriter w m => Class.MonadWriter w (StateT tag s m) where
189− writer = lift . Class.writer
190− tell = lift . Class.tell
191− listen = Lift.liftListen Class.listen
192− pass = Lift.liftPass Class.pass
193−
194−instance Class.MonadError e m => Class.MonadError e (StateT tag s m) where
195− throwError = lift . Class.throwError
196− catchError = Lift.liftCatch Class.catchError
src/Control/Monad/Trans/Ether/State/Strict.hs+2−98
@@ -26,39 +26,11 @@ module Control.Monad.Trans.Ether.State.Strict
2626 -- * State operations
2727 , get
2828 , put
29− -- * Newtype operations
30− , pack
31− , unpack
3229 ) where
3330
3431import Data.Functor.Identity (Identity(..))
35−import Control.Applicative
36−import Control.Monad (MonadPlus)
37−import Control.Monad.Fix (MonadFix)
38−import Control.Monad.Trans.Class (MonadTrans, lift)
39−import Control.Monad.IO.Class (MonadIO)
40−import Control.Monad.Morph (MFunctor)
41−import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
42−import GHC.Generics (Generic)
43−import Data.Coerce (coerce)
44−
45−import qualified Control.Monad.Base as MB
46−import qualified Control.Monad.Trans.Control as MC
4732import qualified Control.Monad.Trans.State.Strict as Trans
48−
49−import qualified Control.Monad.Trans.Lift.StT as Lift
50−import qualified Control.Monad.Trans.Lift.Local as Lift
51−import qualified Control.Monad.Trans.Lift.Catch as Lift
52−import qualified Control.Monad.Trans.Lift.Listen as Lift
53−import qualified Control.Monad.Trans.Lift.Pass as Lift
54−import qualified Control.Monad.Trans.Lift.CallCC as Lift
55−
56−import qualified Control.Monad.Cont.Class as Class
57−import qualified Control.Monad.Reader.Class as Class
58−import qualified Control.Monad.State.Class as Class
59−import qualified Control.Monad.Writer.Class as Class
60−import qualified Control.Monad.Error.Class as Class
61−
33+import Control.Ether.TT
6234
6335-- | The parametrizable state monad.
6436--
@@ -72,50 +44,7 @@ type State tag r = StateT tag r Identity
7244--
7345-- The 'return' function leaves the state unchanged, while '>>=' uses
7446-- the final state of the first computation as the initial state of the second.
75−newtype StateT tag s m a = StateT (Trans.StateT s m a)
76− deriving ( Generic
77− , Functor, Applicative, Alternative, Monad, MonadPlus
78− , MonadFix, MonadTrans, MonadIO, MFunctor
79− , MonadThrow, MonadCatch, MonadMask )
80−
81−-- | Type-restricted 'coerce'.
82−pack :: Trans.StateT s m a -> StateT tag s m a
83−pack = coerce
84−
85−-- | Type-restricted 'coerce'.
86−unpack :: StateT tag s m a -> Trans.StateT s m a
87−unpack = coerce
88−
89−instance MB.MonadBase b m => MB.MonadBase b (StateT tag s m) where
90− liftBase = MB.liftBaseDefault
91−
92−instance MC.MonadTransControl (StateT tag s) where
93− type StT (StateT tag s) a = MC.StT (Trans.StateT s) a
94− liftWith = MC.defaultLiftWith pack unpack
95− restoreT = MC.defaultRestoreT pack
96−
97−instance MC.MonadBaseControl b m => MC.MonadBaseControl b (StateT tag s m) where
98− type StM (StateT tag s m) a = MC.ComposeSt (StateT tag s) m a
99− liftBaseWith = MC.defaultLiftBaseWith
100− restoreM = MC.defaultRestoreM
101−
102−type instance Lift.StT (StateT tag s) a = MC.StT (StateT tag s) a
103−
104−instance Lift.LiftLocal (StateT tag s) where
105− liftLocal = Lift.defaultLiftLocal pack unpack
106−
107−instance Lift.LiftCatch (StateT tag s) where
108− liftCatch = Lift.defaultLiftCatch pack unpack
109−
110−instance Lift.LiftListen (StateT tag s) where
111− liftListen = Lift.defaultLiftListen pack unpack
112−
113−instance Lift.LiftPass (StateT tag s) where
114− liftPass = Lift.defaultLiftPass pack unpack
115−
116−instance Lift.LiftCallCC (StateT tag s) where
117− liftCallCC = Lift.defaultLiftCallCC pack unpack
118− liftCallCC' = Lift.defaultLiftCallCC' pack unpack
47+type StateT tag s = TT tag (Trans.StateT s)
11948
12049tagged :: proxy tag -> Trans.StateT s m a -> StateT tag s m a
12150tagged _ = pack
@@ -169,28 +98,3 @@ get t = tagged t Trans.get
16998-- | Set the value of the state within the monad.
17099put :: Monad m => proxy tag -> s -> StateT tag s m ()
171100put t = tagged t . Trans.put
172−
173−-- Instances for mtl classes
174−
175−instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
176− callCC = Lift.liftCallCC' Class.callCC
177−
178−instance Class.MonadReader r m => Class.MonadReader r (StateT tag s m) where
179− ask = lift Class.ask
180− local = Lift.liftLocal Class.ask Class.local
181− reader = lift . Class.reader
182−
183−instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
184− get = lift Class.get
185− put = lift . Class.put
186− state = lift . Class.state
187−
188−instance Class.MonadWriter w m => Class.MonadWriter w (StateT tag s m) where
189− writer = lift . Class.writer
190− tell = lift . Class.tell
191− listen = Lift.liftListen Class.listen
192− pass = Lift.liftPass Class.pass
193−
194−instance Class.MonadError e m => Class.MonadError e (StateT tag s m) where
195− throwError = lift . Class.throwError
196− catchError = Lift.liftCatch Class.catchError
src/Control/Monad/Trans/Ether/Writer.hs+2−95
@@ -26,9 +26,6 @@ module Control.Monad.Trans.Ether.Writer
2626 , tell
2727 , listen
2828 , pass
29− -- * Newtype operations
30− , pack
31− , unpack
3229 ) where
3330
3431#if __GLASGOW_HASKELL__ < 710
@@ -36,32 +33,8 @@ import Data.Monoid
3633#endif
3734
3835import Data.Functor.Identity (Identity(..))
39−import Control.Applicative
40−import Control.Monad (MonadPlus)
41−import Control.Monad.Fix (MonadFix)
42−import Control.Monad.Trans.Class (MonadTrans, lift)
43−import Control.Monad.IO.Class (MonadIO)
44−import Control.Monad.Morph (MFunctor, MMonad)
45−import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
46−import GHC.Generics (Generic)
47−import Data.Coerce (coerce)
48−
49−import qualified Control.Monad.Base as MB
50−import qualified Control.Monad.Trans.Control as MC
5136import qualified Control.Monad.Trans.Writer.Lazy as Trans
52−
53−import qualified Control.Monad.Trans.Lift.StT as Lift
54−import qualified Control.Monad.Trans.Lift.Local as Lift
55−import qualified Control.Monad.Trans.Lift.Catch as Lift
56−import qualified Control.Monad.Trans.Lift.Listen as Lift
57−import qualified Control.Monad.Trans.Lift.Pass as Lift
58−import qualified Control.Monad.Trans.Lift.CallCC as Lift
59−
60−import qualified Control.Monad.Cont.Class as Class
61−import qualified Control.Monad.Reader.Class as Class
62−import qualified Control.Monad.State.Class as Class
63−import qualified Control.Monad.Writer.Class as Class
64−import qualified Control.Monad.Error.Class as Class
37+import Control.Ether.TT
6538
6639-- | The parametrizable writer monad.
6740--
@@ -75,50 +48,7 @@ type Writer tag w = WriterT tag w Identity
7548--
7649-- The 'return' function produces the output 'mempty', while '>>=' combines
7750-- the outputs of the subcomputations using 'mappend'.
78−newtype WriterT tag w m a = WriterT (Trans.WriterT w m a)
79− deriving ( Generic
80− , Functor, Applicative, Alternative, Monad, MonadPlus
81− , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
82− , MonadThrow, MonadCatch, MonadMask )
83−
84−-- | Type-restricted 'coerce'.
85−pack :: Trans.WriterT w m a -> WriterT tag w m a
86−pack = coerce
87−
88−-- | Type-restricted 'coerce'.
89−unpack :: WriterT tag w m a -> Trans.WriterT w m a
90−unpack = coerce
91−
92−instance (Monoid w, MB.MonadBase b m) => MB.MonadBase b (WriterT tag w m) where
93− liftBase = MB.liftBaseDefault
94−
95−instance Monoid w => MC.MonadTransControl (WriterT tag w) where
96− type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
97− liftWith = MC.defaultLiftWith pack unpack
98− restoreT = MC.defaultRestoreT pack
99−
100−instance (Monoid w, MC.MonadBaseControl b m) => MC.MonadBaseControl b (WriterT tag w m) where
101− type StM (WriterT tag w m) a = MC.ComposeSt (WriterT tag w) m a
102− liftBaseWith = MC.defaultLiftBaseWith
103− restoreM = MC.defaultRestoreM
104−
105−type instance Lift.StT (WriterT tag w) a = MC.StT (WriterT tag w) a
106−
107−instance Monoid w => Lift.LiftLocal (WriterT tag w) where
108− liftLocal = Lift.defaultLiftLocal pack unpack
109−
110−instance Monoid w => Lift.LiftCatch (WriterT tag w) where
111− liftCatch = Lift.defaultLiftCatch pack unpack
112−
113−instance Monoid w => Lift.LiftListen (WriterT tag w) where
114− liftListen = Lift.defaultLiftListen pack unpack
115−
116−instance Monoid w' => Lift.LiftPass (WriterT tag w') where
117− liftPass = Lift.defaultLiftPass pack unpack
118−
119−instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
120− liftCallCC = Lift.defaultLiftCallCC pack unpack
121− liftCallCC' = Lift.defaultLiftCallCC pack unpack
51+type WriterT tag w = TT tag (Trans.WriterT w)
12252
12353tagged :: proxy tag -> Trans.WriterT w m a -> WriterT tag w m a
12454tagged _ = pack
@@ -167,26 +97,3 @@ listen t m = tagged t $ Trans.listen (untagged t m)
16797-- value, applying the function to the accumulator.
16898pass :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
16999pass t m = tagged t $ Trans.pass (untagged t m)
170−
171−instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
172− callCC = Lift.liftCallCC Class.callCC
173−
174−instance (Monoid w, Class.MonadReader r m) => Class.MonadReader r (WriterT tag w m) where
175− ask = lift Class.ask
176− local = Lift.liftLocal Class.ask Class.local
177− reader = lift . Class.reader
178−
179−instance (Monoid w, Class.MonadState s m) => Class.MonadState s (WriterT tag w m) where
180− get = lift Class.get
181− put = lift . Class.put
182− state = lift . Class.state
183−
184−instance (Monoid w, Class.MonadWriter w' m) => Class.MonadWriter w' (WriterT tag w m) where
185− writer = lift . Class.writer
186− tell = lift . Class.tell
187− listen = Lift.liftListen Class.listen
188− pass = Lift.liftPass Class.pass
189−
190−instance (Monoid w, Class.MonadError e m) => Class.MonadError e (WriterT tag w m) where
191− throwError = lift . Class.throwError
192− catchError = Lift.liftCatch Class.catchError
stack.yaml+1−1
@@ -2,4 +2,4 @@ flags: {}
22packages:
33- '.'
44extra-deps: []
5−resolver: lts-3.10
5+resolver: lts-5.0
travis/shc.shnew file+4
@@ -0,0 +1,4 @@
1+if [ -n "$COVERAGE" ]; then
2+ curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.3.0/shc-linux-x64-7.10.2.tar.bz2 | tar -xvj
3+ ./shc ether regression
4+fi
travis/test.shnew file+7
@@ -0,0 +1,7 @@
1+if [ -n "$COVERAGE" ]; then
2+ COVERAGE_OPT="--coverage"
3+fi
4+
5+echo "COVERAGE_OPT=$COVERAGE_OPT"
6+
7+stack test :regression $COVERAGE_OPT --no-terminal