on master help sign in
Ether-flatten prototype (#25)
commit805db1b2f8d85604bd7e14a19ac3845c4a7c3fc6 authorIndex Int <vlad.z.4096@gmail.com> dateTue 3 May 2016, 01:28 (10 years ago) parent550e061
54 files changed+358−46
.travis.yml+1−1 ether-flatten/CHANGELOG.md ether-flatten/LICENSE+30 Setup.hs → ether-flatten/Setup.hs bench/Bench.hs → ether-flatten/bench/Bench.hs+42 ether-flatten/ether-flatten.cabal+61 ether-flatten/src/Control/Ether/Flatten.hs+64 ether-flatten/src/Control/Monad/Ether/Reader/Flatten.hs+66 CHANGELOG.md → ether/CHANGELOG.md LICENSE → ether/LICENSE ether/Setup.hs+2 ether.cabal → ether/ether.cabal−17 src/Control/Ether/Abbr.hs → ether/src/Control/Ether/Abbr.hs src/Control/Ether/Implicit/Abbr.hs → ether/src/Control/Ether/Implicit/Abbr.hs src/Control/Monad/Ether.hs → ether/src/Control/Monad/Ether.hs+1−1 src/Control/Monad/Ether/Except.hs → ether/src/Control/Monad/Ether/Except.hs src/Control/Monad/Ether/Except/Class.hs → ether/src/Control/Monad/Ether/Except/Class.hs src/Control/Monad/Ether/Implicit.hs → ether/src/Control/Monad/Ether/Implicit.hs src/Control/Monad/Ether/Implicit/Except.hs → ether/src/Control/Monad/Ether/Implicit/Except.hs src/Control/Monad/Ether/Implicit/Reader.hs → ether/src/Control/Monad/Ether/Implicit/Reader.hs src/Control/Monad/Ether/Implicit/State.hs → ether/src/Control/Monad/Ether/Implicit/State.hs src/Control/Monad/Ether/Implicit/State/Lazy.hs → ether/src/Control/Monad/Ether/Implicit/State/Lazy.hs src/Control/Monad/Ether/Implicit/State/Strict.hs → ether/src/Control/Monad/Ether/Implicit/State/Strict.hs src/Control/Monad/Ether/Implicit/Writer.hs → ether/src/Control/Monad/Ether/Implicit/Writer.hs src/Control/Monad/Ether/Reader.hs → ether/src/Control/Monad/Ether/Reader.hs src/Control/Monad/Ether/Reader/Class.hs → ether/src/Control/Monad/Ether/Reader/Class.hs src/Control/Monad/Ether/State.hs → ether/src/Control/Monad/Ether/State.hs src/Control/Monad/Ether/State/Class.hs → ether/src/Control/Monad/Ether/State/Class.hs src/Control/Monad/Ether/State/Common.hs → ether/src/Control/Monad/Ether/State/Common.hs src/Control/Monad/Ether/State/Lazy.hs → ether/src/Control/Monad/Ether/State/Lazy.hs src/Control/Monad/Ether/State/Strict.hs → ether/src/Control/Monad/Ether/State/Strict.hs src/Control/Monad/Ether/Writer.hs → ether/src/Control/Monad/Ether/Writer.hs src/Control/Monad/Ether/Writer/Class.hs → ether/src/Control/Monad/Ether/Writer/Class.hs src/Control/Monad/Trans/Ether/Dispatch.hs → ether/src/Control/Monad/Trans/Ether/Dispatch.hs+89−26 src/Control/Monad/Trans/Ether/Except.hs → ether/src/Control/Monad/Trans/Ether/Except.hs src/Control/Monad/Trans/Ether/Reader.hs → ether/src/Control/Monad/Trans/Ether/Reader.hs src/Control/Monad/Trans/Ether/State.hs → ether/src/Control/Monad/Trans/Ether/State.hs src/Control/Monad/Trans/Ether/State/Lazy.hs → ether/src/Control/Monad/Trans/Ether/State/Lazy.hs src/Control/Monad/Trans/Ether/State/Strict.hs → ether/src/Control/Monad/Trans/Ether/State/Strict.hs src/Control/Monad/Trans/Ether/Tagged.hs → ether/src/Control/Monad/Trans/Ether/Tagged.hs src/Control/Monad/Trans/Ether/Writer.hs → ether/src/Control/Monad/Trans/Ether/Writer.hs test/Regression.hs → ether/test/Regression.hs test/Regression/T1.hs → ether/test/Regression/T1.hs test/Regression/T10.hs → ether/test/Regression/T10.hs test/Regression/T11.hs → ether/test/Regression/T11.hs test/Regression/T2.hs → ether/test/Regression/T2.hs test/Regression/T3.hs → ether/test/Regression/T3.hs test/Regression/T4.hs → ether/test/Regression/T4.hs test/Regression/T5.hs → ether/test/Regression/T5.hs test/Regression/T6.hs → ether/test/Regression/T6.hs test/Regression/T7.hs → ether/test/Regression/T7.hs test/Regression/T8.hs → ether/test/Regression/T8.hs test/Regression/T9.hs → ether/test/Regression/T9.hs stack.yaml+2−1
.travis.yml+1−1
@@ -17,7 +17,7 @@ install:
1717
1818script:
1919 - stack test ether:regression --coverage --no-terminal --ghc-options -Werror
20− - stack bench ether:bench --no-terminal --ghc-options -Werror
20+ - stack bench ether-flatten:bench --no-terminal --ghc-options -Werror
2121
2222after_script:
2323 - 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
ether-flatten/CHANGELOG.mdnew file

No changes to the content.

ether-flatten/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2016, Index Int
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Index Int nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Setup.hs → ether-flatten/Setup.hsrenamed

The content is the same.

bench/Bench.hs → ether-flatten/bench/Bench.hsrenamed+42
@@ -1,4 +1,6 @@
11{-# LANGUAGE TypeApplications #-}
2+{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE FunctionalDependencies #-}
24{-# LANGUAGE FlexibleContexts #-}
35{-# LANGUAGE DataKinds #-}
46
@@ -7,6 +9,8 @@ module Main (main) where
79import Criterion.Main
810import qualified Control.Monad.Reader as M
911import qualified Control.Monad.Ether.Reader as E
12+import qualified Control.Monad.Ether.Reader.Flatten as E.F
13+import Control.Ether.Flatten
1014import qualified Control.Lens as L
1115
1216readerSummatorMTL_flat_9
@@ -68,6 +72,41 @@ run_readerSummatorEther_nested_9
6872 . flip (E.runReaderT @1) a9
6973 $ readerSummatorEther_sep_9
7074
75+run_readerSummatorEther_flatten_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> String
76+run_readerSummatorEther_flatten_9
77+ (a1, a2, a3, a4, a5, a6, a7, a8, a9)
78+ =
79+ E.F.runReader
80+ readerSummatorEther_sep_9
81+ ( load @1 a9
82+ . load @2 a8
83+ . load @3 a7
84+ . load @4 a6
85+ . load @5 a5
86+ . load @6 a4
87+ . load @7 a3
88+ . load @8 a2
89+ . load @9 a1
90+ $ Nil )
91+
92+run_readerSummatorEther_flattenhalf_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> String
93+run_readerSummatorEther_flattenhalf_9
94+ (a1, a2, a3, a4, a5, a6, a7, a8, a9)
95+ = flip E.F.runReader
96+ ( load @1 a9
97+ . load @2 a8
98+ . load @3 a7
99+ . load @4 a6
100+ $ Nil )
101+ . flip E.F.runReaderT
102+ ( load @5 a5
103+ . load @6 a4
104+ . load @7 a3
105+ . load @8 a2
106+ . load @9 a1
107+ $ Nil )
108+ $ readerSummatorEther_sep_9
109+
71110tuple_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int)
72111tuple_9 = (1, -2, 3, -4, 5, -6, 7, -8, 9)
73112
@@ -76,4 +115,7 @@ main = do
76115 defaultMain
77116 [ bench "readerSummatorMTL_flat_9" $ nf run_readerSummatorMTL_flat_9 tuple_9
78117 , bench "readerSummatorEther_nested_9" $ nf run_readerSummatorEther_nested_9 tuple_9
118+ , bench "readerSummatorEther_flatten_9" $ nf run_readerSummatorEther_flatten_9 tuple_9
119+ , bench "readerSummatorEther_flattenhalf_9" $
120+ nf run_readerSummatorEther_flattenhalf_9 tuple_9
79121 ]
ether-flatten/ether-flatten.cabalnew file+61
@@ -0,0 +1,61 @@
1+name: ether-flatten
2+version: 0.1.0.0
3+synopsis: Flatten nested monad transformers
4+description:
5+ Flatten nested monad transformers to gain performance.
6+
7+category: Control
8+license: BSD3
9+license-file: LICENSE
10+author: Index Int
11+maintainer: Index Int <vlad.z.4096@gmail.com>
12+homepage: https://int-index.github.io/ether/
13+bug-reports: https://github.com/int-index/ether/issues
14+build-type: Simple
15+cabal-version: >=1.18
16+extra-source-files: CHANGELOG.md
17+
18+source-repository head
19+
20+ type: git
21+ location: git@github.com:int-index/ether.git
22+
23+
24+library
25+
26+ exposed-modules: Control.Monad.Ether.Reader.Flatten
27+ , Control.Ether.Flatten
28+ build-depends: base >=4.9 && <4.10
29+ , ether >=0.5 && <0.6
30+ , transformers >=0.4.2
31+ , transformers-lift >=0.1.0.1
32+ , ghc-prim >=0.3
33+ , lens >=4.14
34+
35+ default-language: Haskell2010
36+ default-extensions: PolyKinds
37+ ScopedTypeVariables
38+ FunctionalDependencies
39+ TypeApplications
40+
41+ hs-source-dirs: src
42+ ghc-options: -Wall
43+
44+
45+benchmark bench
46+
47+ build-depends: base >=4.9 && <4.10
48+ , mtl >=2.2.1
49+ , transformers >=0.4.2
50+ , criterion >=1.1
51+ , lens >=4.14
52+ , ether
53+ , ether-flatten
54+
55+ main-is: Bench.hs
56+
57+ type: exitcode-stdio-1.0
58+ hs-source-dirs: bench
59+ default-language: Haskell2010
60+ ghc-options: -Wall -O2
61+ ghc-prof-options: -fprof-auto
ether-flatten/src/Control/Ether/Flatten.hsnew file+64
@@ -0,0 +1,64 @@
1+{-# LANGUAGE RankNTypes #-}
2+{-# LANGUAGE TypeSynonymInstances #-}
3+{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE TypeOperators #-}
5+{-# LANGUAGE UndecidableInstances #-}
6+{-# LANGUAGE FlexibleInstances #-}
7+{-# LANGUAGE GADTs #-}
8+{-# LANGUAGE TypeFamilies #-}
9+{-# LANGUAGE MagicHash #-}
10+
11+module Control.Ether.Flatten
12+ ( HasLens(..)
13+ , Product(..)
14+ , load
15+ ) where
16+
17+import Control.Lens
18+import GHC.Prim (Proxy#)
19+
20+class HasLens tag outer inner | tag outer -> inner where
21+ lensOf :: Proxy# tag -> Lens' outer inner
22+
23+data Product (ts :: [k]) (as :: [*]) where
24+ Nil :: Product '[] '[]
25+ Cons :: !a -> !(Product ts as) -> Product (t ': ts) (a ': as)
26+
27+load
28+ :: forall tag a tags as
29+ . a -> Product tags as -> Product (tag ': tags) (a ': as)
30+load = Cons
31+
32+productHead ::
33+ Lens
34+ (Product (t1 ': ts) (a ': as))
35+ (Product (t2 ': ts) (b ': as))
36+ a
37+ b
38+productHead =
39+ lens
40+ (\(Cons a _) -> a)
41+ (\(Cons _ as) a -> Cons a as)
42+{-# INLINE productHead #-}
43+
44+productTail ::
45+ Lens
46+ (Product (t ': ts1) (a ': as))
47+ (Product (t ': ts2) (a ': bs))
48+ (Product ts1 as)
49+ (Product ts2 bs)
50+productTail =
51+ lens
52+ (\(Cons _ as) -> as)
53+ (\(Cons a _) as -> Cons a as)
54+{-# INLINE productTail #-}
55+
56+instance a ~ b => HasLens tag (Product (tag ': tags) (a ': as)) b where
57+ lensOf _ = productHead
58+ {-# INLINE lensOf #-}
59+
60+instance {-# OVERLAPPABLE #-}
61+ ( HasLens tag (Product tags as) a
62+ ) => HasLens tag (Product (t ': tags) (b ': as)) a where
63+ lensOf t = productTail . lensOf t
64+ {-# INLINE lensOf #-}
ether-flatten/src/Control/Monad/Ether/Reader/Flatten.hsnew file+66
@@ -0,0 +1,66 @@
1+{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
2+
3+{-# LANGUAGE RankNTypes #-}
4+{-# LANGUAGE TypeSynonymInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE TypeOperators #-}
7+{-# LANGUAGE UndecidableInstances #-}
8+{-# LANGUAGE FlexibleInstances #-}
9+{-# LANGUAGE GADTs #-}
10+{-# LANGUAGE TypeFamilies #-}
11+{-# LANGUAGE MagicHash #-}
12+
13+module Control.Monad.Ether.Reader.Flatten
14+ ( runReader
15+ , runReaderT
16+ ) where
17+
18+import qualified Control.Monad.Trans.Lift.Local as Lift
19+
20+import Data.Functor.Identity
21+import Control.Monad.Ether.Reader.Class as C
22+import Control.Monad.Trans.Ether.Dispatch
23+import qualified Control.Monad.Trans.Reader as T
24+import Control.Lens
25+import Control.Ether.Flatten
26+
27+data K_Flatten t = Flatten [t]
28+
29+type DispatchFlattenT ts = DispatchT (Flatten ts)
30+
31+reflatten
32+ :: forall tagsOld tagsNew m a
33+ . DispatchFlattenT tagsOld m a
34+ -> DispatchFlattenT tagsNew m a
35+reflatten = redispatch
36+{-# INLINE reflatten #-}
37+
38+type DispatchFlattenReaderT ts r m = DispatchFlattenT ts (T.ReaderT r m)
39+
40+instance (Monad m, C.MonadReader tag r m)
41+ => C.MonadReader tag r (DispatchFlattenReaderT '[] payload m) where
42+ ask t = Lift.lift (ask t)
43+ local t = Lift.liftLocal (ask t) (local t)
44+
45+instance (Monad m, HasLens tag payload r)
46+ => C.MonadReader tag r (DispatchFlattenReaderT (tag ': tags) payload m) where
47+ ask t = dispatchT $ view (lensOf t)
48+ local t f = dispatchT . T.local (over (lensOf t) f) . runDispatchT
49+
50+instance {-# OVERLAPPABLE #-}
51+ (Monad m, C.MonadReader tag r (DispatchFlattenReaderT tags payload m))
52+ => C.MonadReader tag r (DispatchFlattenReaderT (t ': tags) payload m) where
53+ ask t = reflatten @tags @(t ': tags) (C.ask t)
54+ local t f = reflatten @tags @(t ': tags) . C.local t f . reflatten @(t ': tags) @tags
55+
56+runReaderT
57+ :: DispatchFlattenReaderT tags (Product tags as) m a
58+ -> Product tags as
59+ -> m a
60+runReaderT m = T.runReaderT (runDispatchT m)
61+
62+runReader
63+ :: DispatchFlattenReaderT tags (Product tags as) Identity a
64+ -> Product tags as
65+ -> a
66+runReader m = T.runReader (runDispatchT m)
CHANGELOG.md → ether/CHANGELOG.mdrenamed

The content is the same.

LICENSE → ether/LICENSErenamed

The content is the same.

ether/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
ether.cabal → ether/ether.cabalrenamed−17
@@ -126,20 +126,3 @@ test-suite regression
126126 TypeFamilies
127127 TypeOperators
128128 ghc-options: -Wall -fno-warn-missing-signatures
129−
130−
131−benchmark bench
132−
133− build-depends: base >=4.9 && <4.10
134− , mtl >=2.2.1
135− , transformers >=0.4.2
136− , criterion >=1.1
137− , lens >=4.14
138− , ether
139−
140− main-is: Bench.hs
141−
142− type: exitcode-stdio-1.0
143− hs-source-dirs: bench
144− default-language: Haskell2010
145− ghc-options: -Wall -O2
src/Control/Ether/Abbr.hs → ether/src/Control/Ether/Abbr.hsrenamed

The content is the same.

src/Control/Ether/Implicit/Abbr.hs → ether/src/Control/Ether/Implicit/Abbr.hsrenamed

The content is the same.

src/Control/Monad/Ether.hs → ether/src/Control/Monad/Ether.hsrenamed+1−1
@@ -10,4 +10,4 @@ import Control.Monad.Ether.Reader as X
1010import Control.Monad.Ether.Writer as X
1111import Control.Monad.Ether.State as X
1212import Control.Monad.Ether.Except as X
13−import Control.Monad.Trans.Ether.Dispatch as X
13+import Control.Monad.Trans.Ether.Dispatch as X (tagAttach, tagReplace)
src/Control/Monad/Ether/Except.hs → ether/src/Control/Monad/Ether/Except.hsrenamed

The content is the same.

src/Control/Monad/Ether/Except/Class.hs → ether/src/Control/Monad/Ether/Except/Class.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit.hs → ether/src/Control/Monad/Ether/Implicit.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/Except.hs → ether/src/Control/Monad/Ether/Implicit/Except.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/Reader.hs → ether/src/Control/Monad/Ether/Implicit/Reader.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/State.hs → ether/src/Control/Monad/Ether/Implicit/State.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/State/Lazy.hs → ether/src/Control/Monad/Ether/Implicit/State/Lazy.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/State/Strict.hs → ether/src/Control/Monad/Ether/Implicit/State/Strict.hsrenamed

The content is the same.

src/Control/Monad/Ether/Implicit/Writer.hs → ether/src/Control/Monad/Ether/Implicit/Writer.hsrenamed

The content is the same.

src/Control/Monad/Ether/Reader.hs → ether/src/Control/Monad/Ether/Reader.hsrenamed

The content is the same.

src/Control/Monad/Ether/Reader/Class.hs → ether/src/Control/Monad/Ether/Reader/Class.hsrenamed

The content is the same.

src/Control/Monad/Ether/State.hs → ether/src/Control/Monad/Ether/State.hsrenamed

The content is the same.

src/Control/Monad/Ether/State/Class.hs → ether/src/Control/Monad/Ether/State/Class.hsrenamed

The content is the same.

src/Control/Monad/Ether/State/Common.hs → ether/src/Control/Monad/Ether/State/Common.hsrenamed

The content is the same.

src/Control/Monad/Ether/State/Lazy.hs → ether/src/Control/Monad/Ether/State/Lazy.hsrenamed

The content is the same.

src/Control/Monad/Ether/State/Strict.hs → ether/src/Control/Monad/Ether/State/Strict.hsrenamed

The content is the same.

src/Control/Monad/Ether/Writer.hs → ether/src/Control/Monad/Ether/Writer.hsrenamed

The content is the same.

src/Control/Monad/Ether/Writer/Class.hs → ether/src/Control/Monad/Ether/Writer/Class.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/Dispatch.hs → ether/src/Control/Monad/Trans/Ether/Dispatch.hsrenamed+89−26
@@ -43,22 +43,23 @@ module Control.Monad.Trans.Ether.Dispatch
4343 (
4444 -- * The DispatchT monad transformer
4545 DispatchT
46+ , dispatchT
47+ , runDispatchT
48+ , redispatch
4649 -- * Dispatch types and functions
4750 , K_TagAttach(..)
48− , K_TagReplace(..)
4951 , tagAttach
52+ , K_TagReplace(..)
5053 , tagReplace
5154 ) where
5255
5356import Control.Applicative
5457import Control.Monad (MonadPlus)
5558import Control.Monad.Fix (MonadFix)
56−import Control.Monad.Trans.Class (MonadTrans)
59+import Control.Monad.Trans.Class (MonadTrans, lift)
5760import Control.Monad.IO.Class (MonadIO)
5861import Control.Monad.Morph (MFunctor, MMonad)
5962import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
60−import GHC.Generics (Generic)
61−import Data.Coerce (coerce)
6263
6364import qualified Control.Monad.Base as MB
6465import qualified Control.Monad.Trans.Control as MC
@@ -81,16 +82,14 @@ import Control.Monad.Ether.State.Common as A
8182import Control.Monad.Ether.Except as A
8283import Control.Monad.Ether.Writer as A
8384
84−import qualified Control.Monad.Reader as Class
85−import qualified Control.Monad.State as Class
86−import qualified Control.Monad.Except as Class
87−import qualified Control.Monad.Writer as Class
85+import qualified Control.Monad.Cont.Class as Class
86+import qualified Control.Monad.Reader.Class as Class
87+import qualified Control.Monad.State.Class as Class
88+import qualified Control.Monad.Writer.Class as Class
89+import qualified Control.Monad.Error.Class as Class
8890
89−-- | Encode type-level information for 'tagAttach'.
90−data K_TagAttach t = TagAttach t
91−
92−-- | Encode type-level information for 'tagReplace'.
93−data K_TagReplace tOld tNew = TagReplace tOld tNew
91+import GHC.Generics (Generic)
92+import Data.Coerce (coerce)
9493
9594-- | Wrap a monad to change its tags. Under the hood this is
9695-- simply 'Trans.IdentityT', all the work is happening on the type level.
@@ -101,17 +100,26 @@ newtype DispatchT dp m a = DispatchT (Trans.IdentityT m a)
101100 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
102101 , MonadThrow, MonadCatch, MonadMask )
103102
104−type DispatchTagAttachT t = DispatchT (TagAttach t)
105−type DispatchTagReplaceT tOld tNew = DispatchT (TagReplace tOld tNew)
106−
107103-- | Type-restricted 'coerce'.
108−pack :: Trans.IdentityT m a -> DispatchT dp m a
104+pack :: forall dp m a . Trans.IdentityT m a -> DispatchT dp m a
109105pack = coerce
110106
111107-- | Type-restricted 'coerce'.
112−unpack :: DispatchT dp m a -> Trans.IdentityT m a
108+unpack :: forall dp m a . DispatchT dp m a -> Trans.IdentityT m a
113109unpack = coerce
114110
111+-- | Type-restricted 'coerce'.
112+dispatchT :: forall dp m a . m a -> DispatchT dp m a
113+dispatchT = coerce
114+
115+-- | Type-restricted 'coerce'.
116+runDispatchT :: forall dp m a . DispatchT dp m a -> m a
117+runDispatchT = coerce
118+
119+-- | Type-restricted 'coerce'.
120+redispatch :: forall dp dp' m a . DispatchT dp m a -> DispatchT dp' m a
121+redispatch = coerce
122+
115123instance MB.MonadBase b m => MB.MonadBase b (DispatchT dp m) where
116124 liftBase = MB.liftBaseDefault
117125
@@ -143,16 +151,62 @@ instance Lift.LiftCallCC (DispatchT dp) where
143151 liftCallCC = Lift.defaultLiftCallCC pack unpack
144152 liftCallCC' = Lift.defaultLiftCallCC' pack unpack
145153
146−-- | Attach a tag to untagged transformers.
147−tagAttach :: forall tag m a . DispatchTagAttachT tag m a -> m a
148−tagAttach = coerce
154+-- Instances for mtl classes
155+
156+instance {-# OVERLAPPABLE #-}
157+ ( Class.MonadCont m
158+ , Monad m
159+ ) => Class.MonadCont (DispatchT dp m)
160+ where
161+ callCC = Lift.liftCallCC' Class.callCC
162+
163+instance {-# OVERLAPPABLE #-}
164+ ( Class.MonadReader r m
165+ , Monad m
166+ ) => Class.MonadReader r (DispatchT dp m)
167+ where
168+ ask = lift Class.ask
169+ local = Lift.liftLocal Class.ask Class.local
170+ reader = lift . Class.reader
171+
172+instance {-# OVERLAPPABLE #-}
173+ ( Class.MonadState s m
174+ , Monad m
175+ ) => Class.MonadState s (DispatchT dp m)
176+ where
177+ get = lift Class.get
178+ put = lift . Class.put
179+ state = lift . Class.state
180+
181+instance {-# OVERLAPPABLE #-}
182+ ( Class.MonadWriter w m
183+ , Monad m
184+ ) => Class.MonadWriter w (DispatchT dp m)
185+ where
186+ writer = lift . Class.writer
187+ tell = lift . Class.tell
188+ listen = Lift.liftListen Class.listen
189+ pass = Lift.liftPass Class.pass
190+
191+instance {-# OVERLAPPABLE #-}
192+ ( Class.MonadError e m
193+ , Monad m
194+ ) => Class.MonadError e (DispatchT dp m)
195+ where
196+ throwError = lift . Class.throwError
197+ catchError = Lift.liftCatch Class.catchError
198+
199+
200+-- TagAttach
149201
150−-- | Replace a tag with another tag.
151−tagReplace :: forall tOld tNew m a . DispatchTagReplaceT tOld tNew m a -> m a
152−tagReplace = coerce
202+-- | Encode type-level information for 'tagAttach'.
203+data K_TagAttach t = TagAttach t
153204
205+type DispatchTagAttachT t = DispatchT (TagAttach t)
154206
155−-- TagAttach instances
207+-- | Attach a tag to untagged transformers.
208+tagAttach :: forall tag m a . DispatchTagAttachT tag m a -> m a
209+tagAttach = coerce
156210
157211instance MonadReader tag r m
158212 => Class.MonadReader r (DispatchTagAttachT tag m) where
@@ -177,7 +231,16 @@ instance MonadWriter tag w m
177231 pass = Lift.liftPass (A.pass @tag)
178232
179233
180−-- TagReplace instances
234+-- TagReplace
235+
236+-- | Encode type-level information for 'tagReplace'.
237+data K_TagReplace tOld tNew = TagReplace tOld tNew
238+
239+type DispatchTagReplaceT tOld tNew = DispatchT (TagReplace tOld tNew)
240+
241+-- | Replace a tag with another tag.
242+tagReplace :: forall tOld tNew m a . DispatchTagReplaceT tOld tNew m a -> m a
243+tagReplace = coerce
181244
182245instance MonadReader tNew r m
183246 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
src/Control/Monad/Trans/Ether/Except.hs → ether/src/Control/Monad/Trans/Ether/Except.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/Reader.hs → ether/src/Control/Monad/Trans/Ether/Reader.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/State.hs → ether/src/Control/Monad/Trans/Ether/State.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/State/Lazy.hs → ether/src/Control/Monad/Trans/Ether/State/Lazy.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/State/Strict.hs → ether/src/Control/Monad/Trans/Ether/State/Strict.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/Tagged.hs → ether/src/Control/Monad/Trans/Ether/Tagged.hsrenamed

The content is the same.

src/Control/Monad/Trans/Ether/Writer.hs → ether/src/Control/Monad/Trans/Ether/Writer.hsrenamed

The content is the same.

test/Regression.hs → ether/test/Regression.hsrenamed

The content is the same.

test/Regression/T1.hs → ether/test/Regression/T1.hsrenamed

The content is the same.

test/Regression/T10.hs → ether/test/Regression/T10.hsrenamed

The content is the same.

test/Regression/T11.hs → ether/test/Regression/T11.hsrenamed

The content is the same.

test/Regression/T2.hs → ether/test/Regression/T2.hsrenamed

The content is the same.

test/Regression/T3.hs → ether/test/Regression/T3.hsrenamed

The content is the same.

test/Regression/T4.hs → ether/test/Regression/T4.hsrenamed

The content is the same.

test/Regression/T5.hs → ether/test/Regression/T5.hsrenamed

The content is the same.

test/Regression/T6.hs → ether/test/Regression/T6.hsrenamed

The content is the same.

test/Regression/T7.hs → ether/test/Regression/T7.hsrenamed

The content is the same.

test/Regression/T8.hs → ether/test/Regression/T8.hsrenamed

The content is the same.

test/Regression/T9.hs → ether/test/Regression/T9.hsrenamed

The content is the same.

stack.yaml+2−1
@@ -7,7 +7,8 @@ setup-info:
77 url: https://downloads.haskell.org/~ghc/8.0.1-rc4/ghc-8.0.0.20160421-x86_64-unknown-linux.tar.xz
88
99packages:
10−- '.'
10+- 'ether'
11+- 'ether-flatten'
1112
1213extra-deps:
1314- Glob-0.7.5