on 192fb9f help sign in
.gitignore+1−18
since splitsnapshots
unifiedsplit
@@ -1,21 +1,4 @@
1−# Cabal
2dist
1dist
3−dist-newstyle
2+.stack-work
4.cabal-sandbox/
3.cabal-sandbox/
5cabal.sandbox.config
4cabal.sandbox.config
6−cabal.project.local
7−.ghc.environment*
8−
9−# Profiling
10−*.prof
11−
12−# Stack
13−.stack-work
14−
15−# Emacs
16−TAGS
17−.dir-locals.el
18−
19−# Vim
20−tags
21−*.swp
.travis.yml+22−24
@@ -1,31 +1,29 @@
1−language: nix
1+sudo: false
2
2
3−os:
3+cache:
4− - linux
4+ directories:
5− - osx
5+ - $HOME/.stack/
6−
7−env:
8− - HC=ghc822
9− - HC=ghc844
10− - HC=ghc861
11
6
12before_install:
7before_install:
13− - curl https://raw.githubusercontent.com/monadfix/nix-cabal/master/nix-cabal -o nix-cabal && chmod u+x nix-cabal
8+ - mkdir -p ~/.local/bin
14− - travis_retry ./nix-cabal new-update
9+ - travis_retry curl -L https://github.com/commercialhaskell/stack/releases/download/v1.0.4.3/stack-1.0.4.3-linux-x86_64.tar.gz | tar -xvz
10+ - mv stack-1.0.4.3-linux-x86_64/stack ~/.local/bin
11+ - export PATH=~/.local/bin:$PATH
12+ - stack --version
13+ - stack setup
14+
15+install:
16+ - stack install --only-dependencies --no-terminal
15
17
16script:
18script:
17− - ./nix-cabal new-test ether:regression
19+ - stack test ether-suite:regression --coverage --no-terminal --ghc-options -Werror
18− - ./nix-cabal new-bench ether:bench
20+ - stack bench ether-suite:bench --no-terminal --ghc-options -Werror
19
21
20−cache:
22+after_script:
21− directories:
23+ - 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
22− - ~/.cabal
24+ - ./shc ether-suite regression
23− - ~/.ghc
24
25
25−matrix:
26+addons:
26− # broken at the moment
27+ apt:
27− exclude:
28+ packages:
28− - os: osx
29+ - libgmp-dev
29− env: HC=ghc822
30− - os: osx
31− env: HC=ghc861
README.md+17
@@ -2,8 +2,25 @@
2
2
3[![Build Status](https://img.shields.io/travis/int-index/ether.svg)](https://travis-ci.org/int-index/ether)
3[![Build Status](https://img.shields.io/travis/int-index/ether.svg)](https://travis-ci.org/int-index/ether)
4[![Hackage](https://img.shields.io/hackage/v/ether.svg)](https://hackage.haskell.org/package/ether)
4[![Hackage](https://img.shields.io/hackage/v/ether.svg)](https://hackage.haskell.org/package/ether)
5+[![Coveralls](https://img.shields.io/coveralls/int-index/ether.svg)](https://coveralls.io/github/int-index/ether)
6+[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/int-index/ether)
5
7
6
8
7Ether is a Haskell library that extends [mtl](https://hackage.haskell.org/package/mtl)
9Ether is a Haskell library that extends [mtl](https://hackage.haskell.org/package/mtl)
8and [transformers](https://hackage.haskell.org/package/transformers) with tagged
10and [transformers](https://hackage.haskell.org/package/transformers) with tagged
9monad transformers and classes in a compatible way.
11monad transformers and classes in a compatible way.
12+
13+## Installation
14+
15+You can install `ether 0.4.0.0`
16+
17+1. using Cabal, from Hackage;
18+2. using Stack, from Stackage;
19+3. using Portage, from Gentoo Haskell Overlay.
20+
21+If unsure, use [Stack](https://github.com/commercialhaskell/stack).
22+
23+## Getting Started
24+
25+To get started, read the introduction on the [homepage](https://int-index.github.io/ether/).
26+If you need help with Ether or if you have any questions about it, ask me in the Gitter chat.
bench/Bench.hsdeleted−203
@@ -1,203 +0,0 @@
1−{-# OPTIONS -fno-warn-partial-type-signatures #-}
2−
3−module Main (main) where
4−
5−import Control.DeepSeq
6−import qualified Control.Lens as L
7−import qualified Control.Monad.Reader as M
8−import qualified Control.Monad.State as M
9−import Criterion.Main
10−import Ether
11−import TupleInstances ()
12−
13−id' :: a -> a
14−id' = id
15−{-# NOINLINE id' #-}
16−
17−readerCombinerMTL_flat_9
18− :: M.MonadReader (Int, Int, Int, Int, Int, Int, Int, Int, Int) m
19− => m ()
20−readerCombinerMTL_flat_9 = do
21− rnf <$> sequenceA
22− [ L.view L._1
23− , L.view L._2
24− , L.view L._3
25− , L.view L._4
26− , L.view L._5
27− , L.view L._6
28− , L.view L._7
29− , L.view L._8
30− , L.view L._9 ]
31−{-# NOINLINE readerCombinerMTL_flat_9 #-}
32−
33−stateCombinerMTL_flat_9
34− :: M.MonadState (Int, Int, Int, Int, Int, Int, Int, Int, Int) m
35− => m ()
36−stateCombinerMTL_flat_9 = do
37− M.modify (L.over L._1 id')
38− M.modify (L.over L._2 id')
39− M.modify (L.over L._3 id')
40− M.modify (L.over L._4 id')
41− M.modify (L.over L._5 id')
42− M.modify (L.over L._6 id')
43− M.modify (L.over L._7 id')
44− M.modify (L.over L._8 id')
45− M.modify (L.over L._9 id')
46− rnf <$> sequenceA
47− [ L.use L._1
48− , L.use L._2
49− , L.use L._3
50− , L.use L._4
51− , L.use L._5
52− , L.use L._6
53− , L.use L._7
54− , L.use L._8
55− , L.use L._9 ]
56−{-# NOINLINE stateCombinerMTL_flat_9 #-}
57−
58−run_readerCombinerMTL_flat_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> ()
59−run_readerCombinerMTL_flat_9
60− (a1, a2, a3, a4, a5, a6, a7, a8, a9) =
61− M.runReader readerCombinerMTL_flat_9 (a9, a8, a7, a6, a5, a4, a3, a2, a1)
62−
63−run_stateCombinerMTL_flat_9 ::
64− (Int, Int, Int, Int, Int, Int, Int, Int, Int) ->
65− ((), (Int, Int, Int, Int, Int, Int, Int, Int, Int))
66−run_stateCombinerMTL_flat_9
67− (a1, a2, a3, a4, a5, a6, a7, a8, a9) =
68− M.runState stateCombinerMTL_flat_9 (a9, a8, a7, a6, a5, a4, a3, a2, a1)
69−
70−readerCombinerEther_sep_9
71− :: ( MonadReader 1 Int m
72− , MonadReader 2 Int m
73− , MonadReader 3 Int m
74− , MonadReader 4 Int m
75− , MonadReader 5 Int m
76− , MonadReader 6 Int m
77− , MonadReader 7 Int m
78− , MonadReader 8 Int m
79− , MonadReader 9 Int m )
80− => m ()
81−readerCombinerEther_sep_9 = rnf <$> sequenceA
82− [ ask @1
83− , ask @2
84− , ask @3
85− , ask @4
86− , ask @5
87− , ask @6
88− , ask @7
89− , ask @8
90− , ask @9 ]
91−{-# NOINLINE readerCombinerEther_sep_9 #-}
92−
93−stateCombinerEther_sep_9
94− :: ( MonadState 1 Int m
95− , MonadState 2 Int m
96− , MonadState 3 Int m
97− , MonadState 4 Int m
98− , MonadState 5 Int m
99− , MonadState 6 Int m
100− , MonadState 7 Int m
101− , MonadState 8 Int m
102− , MonadState 9 Int m )
103− => m ()
104−stateCombinerEther_sep_9 = do
105− modify @1 id'
106− modify @2 id'
107− modify @3 id'
108− modify @4 id'
109− modify @5 id'
110− modify @6 id'
111− modify @7 id'
112− modify @8 id'
113− modify @9 id'
114− rnf <$> sequenceA
115− [ get @1
116− , get @2
117− , get @3
118− , get @4
119− , get @5
120− , get @6
121− , get @7
122− , get @8
123− , get @9 ]
124−{-# NOINLINE stateCombinerEther_sep_9 #-}
125−
126−run_readerCombinerEther_nested_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> ()
127−run_readerCombinerEther_nested_9
128− (a1, a2, a3, a4, a5, a6, a7, a8, a9)
129− = flip (runReader @9) a1
130− . flip (runReaderT @8) a2
131− . flip (runReaderT @7) a3
132− . flip (runReaderT @6) a4
133− . flip (runReaderT @5) a5
134− . flip (runReaderT @4) a6
135− . flip (runReaderT @3) a7
136− . flip (runReaderT @2) a8
137− . flip (runReaderT @1) a9
138− $ readerCombinerEther_sep_9
139−
140−run_readerCombinerEther_flatten_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> ()
141−run_readerCombinerEther_flatten_9
142− (a1, a2, a3, a4, a5, a6, a7, a8, a9)
143− =
144− runReaders
145− readerCombinerEther_sep_9
146− ( Tagged @1 a9,
147− Tagged @2 a8,
148− Tagged @3 a7,
149− Tagged @4 a6,
150− Tagged @5 a5,
151− Tagged @6 a4,
152− Tagged @7 a3,
153− Tagged @8 a2,
154− Tagged @9 a1 )
155−
156−run_readerCombinerEther_flattenhalf_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> ()
157−run_readerCombinerEther_flattenhalf_9
158− (a1, a2, a3, a4, a5, a6, a7, a8, a9) =
159− flip runReaders
160− ( Tagged @1 a9,
161− Tagged @2 a8,
162− Tagged @3 a7,
163− Tagged @4 a6 ) .
164− flip runReadersT
165− ( Tagged @5 a5,
166− Tagged @6 a4,
167− Tagged @7 a3,
168− Tagged @8 a2,
169− Tagged @9 a1 ) $
170− readerCombinerEther_sep_9
171−
172−run_stateCombinerEther_flatten_9 ::
173− (Int, Int, Int, Int, Int, Int, Int, Int, Int) ->
174− ((), _)
175−run_stateCombinerEther_flatten_9
176− (a1, a2, a3, a4, a5, a6, a7, a8, a9)
177− =
178− runStates
179− stateCombinerEther_sep_9
180− ( Tagged @1 a9,
181− Tagged @2 a8,
182− Tagged @3 a7,
183− Tagged @4 a6,
184− Tagged @5 a5,
185− Tagged @6 a4,
186− Tagged @7 a3,
187− Tagged @8 a2,
188− Tagged @9 a1 )
189−
190−tuple_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int)
191−tuple_9 = (1, -2, 3, -4, 5, -6, 7, -8, 9)
192−
193−main :: IO ()
194−main = do
195− defaultMain
196− [ bench "readerCombinerMTL_flat_9" $ nf run_readerCombinerMTL_flat_9 tuple_9
197− , bench "readerCombinerEther_nested_9" $ nf run_readerCombinerEther_nested_9 tuple_9
198− , bench "readerCombinerEther_flatten_9" $ nf run_readerCombinerEther_flatten_9 tuple_9
199− , bench "readerCombinerEther_flattenhalf_9" $
200− nf run_readerCombinerEther_flattenhalf_9 tuple_9
201− , bench "stateCombinerMTL_flat_9" $ nf run_stateCombinerMTL_flat_9 tuple_9
202− , bench "stateCombinerEther_flatten_9" $ nf run_stateCombinerEther_flatten_9 tuple_9
203− ]
bench/TupleInstances.hsdeleted−9
@@ -1,9 +0,0 @@
1−{-# OPTIONS -fno-warn-orphans #-}
2−{-# LANGUAGE CPP #-}
3−
4−module TupleInstances () where
5−
6−#ifdef DISABLE_TUP_INSTANCES
7−import Ether.Internal (makeTupleInstancesHasLens)
8−makeTupleInstancesHasLens [4,5,9]
9−#endif
ether-flatten/CHANGELOG.mdnew file

No changes to the content.

LICENSE → ether-flatten/LICENSErenamed+2−2
@@ -1,4 +1,4 @@
1−Copyright (c) 2017, Vladislav Zavialov
1+Copyright (c) 2016, Index Int
2
2
3All rights reserved.
3All rights reserved.
4
4
@@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met:
13 disclaimer in the documentation and/or other materials provided
13 disclaimer in the documentation and/or other materials provided
14 with the distribution.
14 with the distribution.
15
15
16− * Neither the name of Vladislav Zavialov nor the names of other
16+ * Neither the name of Index Int nor the names of other
17 contributors may be used to endorse or promote products derived
17 contributors may be used to endorse or promote products derived
18 from this software without specific prior written permission.
18 from this software without specific prior written permission.
19
19
Setup.hs → ether-flatten/Setup.hsrenamed

The content is the same.

ether-flatten/ether-flatten.cabalnew file+42
@@ -0,0 +1,42 @@
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
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)
ether-suite/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
ether-suite/bench/Bench.hsnew file+121
@@ -0,0 +1,121 @@
1+{-# LANGUAGE TypeApplications #-}
2+{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE FunctionalDependencies #-}
4+{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE DataKinds #-}
6+
7+module Main (main) where
8+
9+import Criterion.Main
10+import qualified Control.Monad.Reader as M
11+import qualified Control.Monad.Ether.Reader as E
12+import qualified Control.Monad.Ether.Reader.Flatten as E.F
13+import Control.Ether.Flatten
14+import qualified Control.Lens as L
15+
16+readerSummatorMTL_flat_9
17+ :: M.MonadReader (Int, Int, Int, Int, Int, Int, Int, Int, Int) m
18+ => m String
19+readerSummatorMTL_flat_9 = do
20+ concat <$> sequenceA
21+ [ show <$> L.view L._1
22+ , show <$> L.view L._2
23+ , show <$> L.view L._3
24+ , show <$> L.view L._4
25+ , show <$> L.view L._5
26+ , show <$> L.view L._6
27+ , show <$> L.view L._7
28+ , show <$> L.view L._8
29+ , show <$> L.view L._9 ]
30+{-# NOINLINE readerSummatorMTL_flat_9 #-}
31+
32+run_readerSummatorMTL_flat_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> String
33+run_readerSummatorMTL_flat_9
34+ (a1, a2, a3, a4, a5, a6, a7, a8, a9)
35+ = M.runReader readerSummatorMTL_flat_9
36+ $ (a9, a8, a7, a6, a5, a4, a3, a2, a1)
37+
38+readerSummatorEther_sep_9
39+ :: ( E.MonadReader 1 Int m
40+ , E.MonadReader 2 Int m
41+ , E.MonadReader 3 Int m
42+ , E.MonadReader 4 Int m
43+ , E.MonadReader 5 Int m
44+ , E.MonadReader 6 Int m
45+ , E.MonadReader 7 Int m
46+ , E.MonadReader 8 Int m
47+ , E.MonadReader 9 Int m )
48+ => m String
49+readerSummatorEther_sep_9 = concat <$> sequenceA
50+ [ show <$> E.ask @1
51+ , show <$> E.ask @2
52+ , show <$> E.ask @3
53+ , show <$> E.ask @4
54+ , show <$> E.ask @5
55+ , show <$> E.ask @6
56+ , show <$> E.ask @7
57+ , show <$> E.ask @8
58+ , show <$> E.ask @9 ]
59+{-# NOINLINE readerSummatorEther_sep_9 #-}
60+
61+run_readerSummatorEther_nested_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> String
62+run_readerSummatorEther_nested_9
63+ (a1, a2, a3, a4, a5, a6, a7, a8, a9)
64+ = flip (E.runReader @9) a1
65+ . flip (E.runReaderT @8) a2
66+ . flip (E.runReaderT @7) a3
67+ . flip (E.runReaderT @6) a4
68+ . flip (E.runReaderT @5) a5
69+ . flip (E.runReaderT @4) a6
70+ . flip (E.runReaderT @3) a7
71+ . flip (E.runReaderT @2) a8
72+ . flip (E.runReaderT @1) a9
73+ $ readerSummatorEther_sep_9
74+
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+
110+tuple_9 :: (Int, Int, Int, Int, Int, Int, Int, Int, Int)
111+tuple_9 = (1, -2, 3, -4, 5, -6, 7, -8, 9)
112+
113+main :: IO ()
114+main = do
115+ defaultMain
116+ [ bench "readerSummatorMTL_flat_9" $ nf run_readerSummatorMTL_flat_9 tuple_9
117+ , 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
121+ ]
ether-suite/ether-suite.cabalnew file+70
@@ -0,0 +1,70 @@
1+name: ether-suite
2+version: 0.1.0.0
3+build-type: Simple
4+cabal-version: >=1.18
5+
6+library
7+ -- Dummy section.
8+ default-language: Haskell2010
9+
10+test-suite regression
11+
12+ build-depends: base >=4.9 && <4.10
13+ , transformers >=0.4.2
14+ , mtl >=2.2.1
15+ , tasty >=0.10
16+ , tasty-quickcheck >=0.8
17+ , QuickCheck >=2.8
18+ , ghc-prim >=0.3
19+ , lens >=4.14
20+ , ether
21+ , ether-zoom
22+
23+ main-is: Regression.hs
24+ other-modules: Regression.T1
25+ Regression.T2
26+ Regression.T3
27+ Regression.T4
28+ Regression.T5
29+ Regression.T6
30+ Regression.T7
31+ Regression.T8
32+ Regression.T9
33+ Regression.T10
34+ Regression.T11
35+ Regression.T12
36+
37+ type: exitcode-stdio-1.0
38+ hs-source-dirs: test
39+ default-language: Haskell2010
40+ default-extensions: ConstraintKinds
41+ DataKinds
42+ EmptyDataDecls
43+ FlexibleContexts
44+ GeneralizedNewtypeDeriving
45+ LambdaCase
46+ PolyKinds
47+ ScopedTypeVariables
48+ TypeApplications
49+ TypeFamilies
50+ TypeOperators
51+ ghc-options: -Wall -fno-warn-missing-signatures
52+
53+
54+benchmark bench
55+
56+ build-depends: base >=4.9 && <4.10
57+ , mtl >=2.2.1
58+ , transformers >=0.4.2
59+ , criterion >=1.1
60+ , lens >=4.14
61+ , ether
62+ , ether-flatten
63+
64+ main-is: Bench.hs
65+
66+ type: exitcode-stdio-1.0
67+ hs-source-dirs: bench
68+ default-language: Haskell2010
69+ ghc-options: -Wall -O2
70+ ghc-prof-options: -fprof-auto
test/Regression.hs → ether-suite/test/Regression.hsrenamed

The content is the same.

test/Regression/T1.hs → ether-suite/test/Regression/T1.hsrenamed+5−16
@@ -1,8 +1,7 @@
1module Regression.T1 (test1) where
1module Regression.T1 (test1) where
2
2
3−import Ether
3+import Control.Monad.Ether
4−import TupleInstances ()
4+import Control.Ether.Abbr
5−import Data.List (group)
6
5
7import Test.Tasty
6import Test.Tasty
8import Test.Tasty.QuickCheck
7import Test.Tasty.QuickCheck
@@ -11,7 +10,7 @@ data Tag1
11data Tag2
10data Tag2
12
11
13testEther
12testEther
14− :: (MonadReader Tag1 String m, MonadReader Tag2 String m)
13+ :: Ether '[Tag1 --> String, Tag2 --> String] m
15 => m ((String, String), (String, String))
14 => m ((String, String), (String, String))
16testEther = do
15testEther = do
17 s1 <- ask @Tag1
16 s1 <- ask @Tag1
@@ -25,10 +24,6 @@ testEther = do
25
24
26runner1 s1 s2 = flip (runReader @Tag1) s1 . flip (runReaderT @Tag2) s2
25runner1 s1 s2 = flip (runReader @Tag1) s1 . flip (runReaderT @Tag2) s2
27runner2 s1 s2 = flip (runReader @Tag2) s2 . flip (runReaderT @Tag1) s1
26runner2 s1 s2 = flip (runReader @Tag2) s2 . flip (runReaderT @Tag1) s1
28−runner3 s1 s2 = flip runReaders (Tagged @Tag1 s1, Tagged @Tag2 s2)
29−
30−same :: Eq a => [a] -> Bool
31−same = (<=1) . length . group
32
27
33test1 :: TestTree
28test1 :: TestTree
34test1 = testGroup "T1: Reader local environment"
29test1 = testGroup "T1: Reader local environment"
@@ -38,13 +33,7 @@ test1 = testGroup "T1: Reader local environment"
38 , testProperty "runner₂ works"
33 , testProperty "runner₂ works"
39 $ \s1 s2 -> property
34 $ \s1 s2 -> property
40 $ runner2 s1 s2 testEther == ((s1, s2), (s1, map succ s2))
35 $ runner2 s1 s2 testEther == ((s1, s2), (s1, map succ s2))
41− , testProperty "runner₃ works"
42− $ \s1 s2 -> property
43− $ runner3 s1 s2 testEther == ((s1, s2), (s1, map succ s2))
44− , testProperty "runner₁ == runner₂ == runner₃"
36+ , testProperty "runner₁ == runner₂"
45 $ \s1 s2 -> property
37 $ \s1 s2 -> property
46− $ same
47− [ runner1 s1 s2 testEther
38+ $ runner1 s1 s2 testEther == runner2 s1 s2 testEther
48− , runner2 s1 s2 testEther
49− , runner3 s1 s2 testEther ]
50 ]
39 ]
test/Regression/T10.hs → ether-suite/test/Regression/T10.hsrenamed+10−11
@@ -2,23 +2,22 @@ module Regression.T10 (test10) where
2
2
3import Control.Applicative
3import Control.Applicative
4import Data.Functor.Identity
4import Data.Functor.Identity
5−
6−import Ether
5+import qualified Control.Monad.Ether.Implicit as I
7
6
8import Test.Tasty
7import Test.Tasty
9import Test.Tasty.QuickCheck
8import Test.Tasty.QuickCheck
10
9
11−testEther :: Integer -> StateT' Integer Maybe [Integer]
10+testEther :: Integer -> I.StateT Integer Maybe [Integer]
12testEther m = range
11testEther m = range
13 where
12 where
14 range = liftA2 (:) yield (range <|> pure [])
13 range = liftA2 (:) yield (range <|> pure [])
15− yield = stateT' $ \n -> do
14+ yield = I.stateT $ \n -> do
16− guard (n <= m)
15+ I.guard (n <= m)
17 Just (n, n + 1)
16 Just (n, n + 1)
18
17
19−testEther' :: Integer -> State' Integer [Integer]
18+testEther' :: Integer -> I.State Integer [Integer]
20testEther' m =
19testEther' m =
21− stateT' $ Identity . maybe ([], m + 1) id . runStateT' (testEther m)
20+ I.stateT $ Identity . maybe ([], m + 1) id . I.runStateT (testEther m)
22
21
23next1 :: Integer -> Integer -> Maybe Integer
22next1 :: Integer -> Integer -> Maybe Integer
24next1 m n
23next1 m n
@@ -33,11 +32,11 @@ range1 m n
33test10 :: TestTree
32test10 :: TestTree
34test10 = testGroup "T10: Alternative instance"
33test10 = testGroup "T10: Alternative instance"
35 [ testProperty "execStateT works"
34 [ testProperty "execStateT works"
36− $ \m n -> execStateT' (testEther m) n == next1 m n
35+ $ \m n -> I.execStateT (testEther m) n == next1 m n
37 , testProperty "evalStateT works"
36 , testProperty "evalStateT works"
38− $ \m n -> evalStateT' (testEther m) n == range1 m n
37+ $ \m n -> I.evalStateT (testEther m) n == range1 m n
39 , testProperty "execState works"
38 , testProperty "execState works"
40− $ \m n -> execState' (testEther' m) n == m + 1
39+ $ \m n -> I.execState (testEther' m) n == m + 1
41 , testProperty "evalState works"
40 , testProperty "evalState works"
42− $ \m n -> evalState' (testEther' m) n == [n..m]
41+ $ \m n -> I.evalState (testEther' m) n == [n..m]
43 ]
42 ]
test/Regression/T11.hs → ether-suite/test/Regression/T11.hsrenamed+4−4
@@ -1,8 +1,8 @@
1module Regression.T11 (test11) where
1module Regression.T11 (test11) where
2
2
3−import Ether
4−
5import Data.Bool
3import Data.Bool
4+import Control.Monad.Ether
5+
6import qualified Control.Monad.State as T
6import qualified Control.Monad.State as T
7import qualified Control.Monad.Reader as T
7import qualified Control.Monad.Reader as T
8
8
@@ -28,12 +28,12 @@ model n = zipWith ($) (cycle [id, negate]) [n..]
28
28
29runner1 n
29runner1 n
30 = flip (T.runReader) n
30 = flip (T.runReader) n
31− . flip (execLazyStateT @STag) []
31+ . flip (execStateT @STag) []
32 . flip T.evalStateT False
32 . flip T.evalStateT False
33
33
34runner2 n
34runner2 n
35 = flip T.evalState False
35 = flip T.evalState False
36− . flip (execLazyStateT @STag) []
36+ . flip (execStateT @STag) []
37 . flip T.runReaderT n
37 . flip T.runReaderT n
38
38
39test11 :: TestTree
39test11 :: TestTree
test/Regression/T12.hs → ether-suite/test/Regression/T12.hsrenamed+4−3
@@ -1,6 +1,7 @@
1module Regression.T12 (test12) where
1module Regression.T12 (test12) where
2
2
3−import Ether
3+import Control.Monad.Ether.State
4+import Control.Monad.Ether.State.Zoom
4import Control.Lens
5import Control.Lens
5
6
6import Test.Tasty
7import Test.Tasty
@@ -13,8 +14,8 @@ succState = modify @Foo succ
13
14
14testEther :: (Enum a, MonadState Foo (a, a) m) => m (a, a)
15testEther :: (Enum a, MonadState Foo (a, a) m) => m (a, a)
15testEther = do
16testEther = do
16− Ether.zoom @Foo _1 succState
17+ tagZoom @Foo _1 succState
17− Ether.zoom @Foo _2 $ modify @Foo pred
18+ tagZoom @Foo _2 $ modify @Foo pred
18 get @Foo
19 get @Foo
19
20
20model :: Enum a => (a, a) -> (a, a)
21model :: Enum a => (a, a) -> (a, a)
test/Regression/T2.hs → ether-suite/test/Regression/T2.hsrenamed+9−7
@@ -1,18 +1,20 @@
1module Regression.T2 (test2) where
1module Regression.T2 (test2) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+import qualified Control.Monad.Ether.Implicit as I
5+import qualified Control.Ether.Implicit.Abbr as I
4
6
5import Test.Tasty
7import Test.Tasty
6import Test.Tasty.QuickCheck
8import Test.Tasty.QuickCheck
7
9
8−testEther :: (MonadReader' Integer m, MonadReader' Bool m) => m String
10+testEther :: Ether '[I.R Integer, I.R Bool] m => m String
9−testEther = local' (succ :: Integer -> Integer) $ do
11+testEther = I.local (succ :: Integer -> Integer) $ do
10− n :: Integer <- asks' (*2)
12+ n :: Integer <- I.asks (*2)
11− b <- local' not ask'
13+ b <- I.local not I.ask
12 return (if b then "" else show n)
14 return (if b then "" else show n)
13
15
14−runner1 (n :: Integer) = flip runReader' n . flip runReaderT' True
16+runner1 (n :: Integer) = flip I.runReader n . flip I.runReaderT True
15−runner2 (n :: Integer) = flip runReader' True . flip runReaderT' n
17+runner2 (n :: Integer) = flip I.runReader True . flip I.runReaderT n
16
18
17test2 :: TestTree
19test2 :: TestTree
18test2 = testGroup "T2: Implicit tags"
20test2 = testGroup "T2: Implicit tags"
test/Regression/T3.hs → ether-suite/test/Regression/T3.hsrenamed+3−2
@@ -1,6 +1,7 @@
1module Regression.T3 (test3) where
1module Regression.T3 (test3) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+import Control.Monad.Ether
4
5
5import qualified Control.Monad.Reader as T
6import qualified Control.Monad.Reader as T
6import qualified Control.Monad.State as T
7import qualified Control.Monad.State as T
@@ -19,7 +20,7 @@ testMTL = do
19 return (a * b)
20 return (a * b)
20
21
21testEther
22testEther
22− :: (MonadReader STag Int m, MonadState STag Int m, MonadReader RTag Int m)
23+ :: Ether '[STag --> Int, STag <-> Int, RTag --> Int] m
23 => m (Int, Int, Int)
24 => m (Int, Int, Int)
24testEther = local @RTag (*2) $ do
25testEther = local @RTag (*2) $ do
25 a_mul_b <- tagAttach @STag testMTL
26 a_mul_b <- tagAttach @STag testMTL
test/Regression/T4.hs → ether-suite/test/Regression/T4.hsrenamed+3−2
@@ -1,13 +1,14 @@
1module Regression.T4 (test4) where
1module Regression.T4 (test4) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+import Control.Monad.Ether
4
5
5import Test.Tasty
6import Test.Tasty
6import Test.Tasty.QuickCheck
7import Test.Tasty.QuickCheck
7
8
8data RTag
9data RTag
9
10
10−testEther :: MonadReader RTag Int m => m Int
11+testEther :: Ether '[RTag --> Int] m => m Int
11testEther = ask @RTag
12testEther = ask @RTag
12
13
13runner r
14runner r
test/Regression/T5.hs → ether-suite/test/Regression/T5.hsrenamed+11−8
@@ -1,6 +1,9 @@
1module Regression.T5 (test5) where
1module Regression.T5 (test5) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+
5+import qualified Control.Monad.Ether.Implicit as I
6+import qualified Control.Ether.Implicit.Abbr as I
4
7
5import Test.Tasty
8import Test.Tasty
6import Test.Tasty.QuickCheck
9import Test.Tasty.QuickCheck
@@ -13,22 +16,22 @@ incCounter = succ
13
16
14testEther
17testEther
15 :: (Num a, Ord a)
18 :: (Num a, Ord a)
16− => (MonadReader' a m, MonadState' Counter m)
19+ => Ether '[I.R a, I.S Counter] m
17 => m a
20 => m a
18testEther = do
21testEther = do
19− a <- ask'
22+ a <- I.ask
20 if a <= 0
23 if a <= 0
21 then do
24 then do
22− put' (0 :: Counter)
25+ I.put (0 :: Counter)
23 return 1
26 return 1
24 else do
27 else do
25− modify' incCounter -- overriden in the base case
28+ I.modify incCounter -- overriden in the base case
26− b <- runReaderT' testEther (a - 1)
29+ b <- I.runReaderT testEther (a - 1)
27− modify' incCounter
30+ I.modify incCounter
28 return (a * b)
31 return (a * b)
29
32
30runner :: (Num a, Ord a) => a -> (a, Counter)
33runner :: (Num a, Ord a) => a -> (a, Counter)
31−runner a = runState' (runReaderT' testEther a) (0 :: Counter)
34+runner a = I.runState (I.runReaderT testEther a) (0 :: Counter)
32
35
33factorial :: (Num a, Enum a) => a -> a
36factorial :: (Num a, Enum a) => a -> a
34factorial a = product [1..a]
37factorial a = product [1..a]
test/Regression/T6.hs → ether-suite/test/Regression/T6.hsrenamed+16−14
@@ -1,7 +1,10 @@
1module Regression.T6 (test6) where
1module Regression.T6 (test6) where
2
2
3−import Data.Function
3+import Control.Monad
4−import Ether
4+import Control.Ether.Abbr
5+
6+import qualified Control.Monad.Ether.Implicit as I
7+import qualified Control.Ether.Implicit.Abbr as I
5
8
6import Test.Tasty
9import Test.Tasty
7import Test.Tasty.QuickCheck
10import Test.Tasty.QuickCheck
@@ -14,33 +17,32 @@ data NegativeLog a = NegativeLog a
14
17
15testEther
18testEther
16 :: (Floating a, Ord a)
19 :: (Floating a, Ord a)
17− => (MonadExcept' DivideByZero m, MonadExcept' (NegativeLog a) m)
20+ => Ether '[I.E DivideByZero, I.E (NegativeLog a)] m
18 => a -> a -> m a
21 => a -> a -> m a
19testEther a b = do
22testEther a b = do
20− when (b == 0) (throw' DivideByZero)
23+ when (b == 0) (I.throw DivideByZero)
21 let d = a / b
24 let d = a / b
22− when (d < 0) (throw' (NegativeLog d))
25+ when (d < 0) (I.throw (NegativeLog d))
23 return (log d)
26 return (log d)
24
27
28+-- Copied verbatim from "Data.Function" to support @base < 4.8@.
29+(&) :: a -> (a -> b) -> b
30+x & f = f x
31+
25handleNegativeLog (NegativeLog (x :: Double)) = "nl: " ++ show x
32handleNegativeLog (NegativeLog (x :: Double)) = "nl: " ++ show x
26handleDivideByZero DivideByZero = "dz"
33handleDivideByZero DivideByZero = "dz"
27
34
28−handleT' :: Functor m => (e -> a) -> ExceptT' e m a -> m a
29−handleT' h m = fmap (either h id) (runExceptT' m)
30−
31runner1 :: Double -> Double -> String
35runner1 :: Double -> Double -> String
32runner1 a b = do
36runner1 a b = do
33 (show `fmap` testEther a b)
37 (show `fmap` testEther a b)
34− & handleT' handleNegativeLog
38+ & I.handleT handleNegativeLog
35− & handleT' handleDivideByZero
39+ & I.handle handleDivideByZero
36− & runIdentity
37
40
38runner2 :: Double -> Double -> String
41runner2 :: Double -> Double -> String
39runner2 a b = do
42runner2 a b = do
40 (show `fmap` testEther a b)
43 (show `fmap` testEther a b)
41− & handleT' handleDivideByZero
44+ & I.handleT handleDivideByZero
42− & handleT' handleNegativeLog
45+ & I.handle handleNegativeLog
43− & runIdentity
44
46
45logDiv :: Double -> Double -> String
47logDiv :: Double -> Double -> String
46logDiv a b
48logDiv a b
test/Regression/T7.hs → ether-suite/test/Regression/T7.hsrenamed+1−1
@@ -3,7 +3,7 @@ module Regression.T7 (test7) where
3import Data.Monoid
3import Data.Monoid
4import Control.Monad
4import Control.Monad
5
5
6−import Ether
6+import Control.Monad.Ether
7import qualified Control.Monad.Writer as T
7import qualified Control.Monad.Writer as T
8
8
9import Test.Tasty
9import Test.Tasty
test/Regression/T8.hs → ether-suite/test/Regression/T8.hsrenamed+3−2
@@ -1,6 +1,7 @@
1module Regression.T8 (test8) where
1module Regression.T8 (test8) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+import Control.Monad.Ether
4
5
5import qualified Control.Monad.State as T
6import qualified Control.Monad.State as T
6
7
@@ -17,7 +18,7 @@ testMTL2 :: T.MonadState Bool m => m ()
17testMTL2 = T.modify not
18testMTL2 = T.modify not
18
19
19testEther
20testEther
20− :: (MonadState Foo Int m, MonadState Bar Bool m)
21+ :: Ether '[Foo <-> Int, Bar <-> Bool] m
21 => m String
22 => m String
22testEther = do
23testEther = do
23 tagAttach @Foo testMTL1
24 tagAttach @Foo testMTL1
test/Regression/T9.hs → ether-suite/test/Regression/T9.hsrenamed+5−4
@@ -1,6 +1,7 @@
1module Regression.T9 (test9) where
1module Regression.T9 (test9) where
2
2
3−import Ether
3+import Control.Ether.Abbr
4+import Control.Monad.Ether
4
5
5import Test.Tasty
6import Test.Tasty
6import Test.Tasty.QuickCheck
7import Test.Tasty.QuickCheck
@@ -8,16 +9,16 @@ import Test.Tasty.QuickCheck
8data Foo
9data Foo
9data Bar
10data Bar
10
11
11−testEther1 :: MonadState Foo Int m => m String
12+testEther1 :: Ether '[Foo <-> Int] m => m String
12testEther1 = do
13testEther1 = do
13 modify @Foo negate
14 modify @Foo negate
14 gets @Foo show
15 gets @Foo show
15
16
16−testEther2 :: MonadState Bar Int m => m String
17+testEther2 :: Ether '[Bar <-> Int] m => m String
17testEther2 = tagReplace @Foo @Bar testEther1
18testEther2 = tagReplace @Foo @Bar testEther1
18
19
19testEther
20testEther
20− :: (MonadState Foo Int m, MonadState Bar Int m)
21+ :: Ether '[Foo <-> Int, Bar <-> Int] m
21 => m String
22 => m String
22testEther = do
23testEther = do
23 a <- testEther1
24 a <- testEther1
ether-zoom/CHANGELOG.mdnew file

No changes to the content.

ether-zoom/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.
ether-zoom/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
ether-zoom/ether-zoom.cabalnew file+39
@@ -0,0 +1,39 @@
1+name: ether-zoom
2+version: 0.1.0.0
3+synopsis: Zoom for the state monad
4+description:
5+ Zoom into parts of a state using a lens.
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.State.Zoom
27+ build-depends: base >=4.9 && <4.10
28+ , ether >=0.5 && <0.6
29+ , lens >=4.14
30+ , reflection >=2.1
31+
32+ default-language: Haskell2010
33+ default-extensions: PolyKinds
34+ ScopedTypeVariables
35+ FunctionalDependencies
36+ TypeApplications
37+
38+ hs-source-dirs: src
39+ ghc-options: -Wall
ether-zoom/src/Control/Monad/Ether/State/Zoom.hsnew file+39
@@ -0,0 +1,39 @@
1+{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
2+
3+{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE RankNTypes #-}
5+{-# LANGUAGE TypeSynonymInstances #-}
6+{-# LANGUAGE FlexibleInstances #-}
7+{-# LANGUAGE FlexibleContexts #-}
8+{-# LANGUAGE UndecidableInstances #-}
9+
10+module Control.Monad.Ether.State.Zoom
11+ ( K_TagZoom(..)
12+ , tagZoom
13+ ) where
14+
15+import Control.Lens
16+import Data.Reflection
17+import Control.Monad.Trans.Ether.Dispatch
18+import Control.Monad.Ether.State.Class
19+import Data.Proxy
20+
21+-- | Encode type-level information for 'tagZoom'.
22+data K_TagZoom t z = TagZoom t z
23+
24+type DispatchTagZoomT t (z :: *) = DispatchT (TagZoom t z)
25+
26+-- | Zoom into a part of a state using a lens.
27+tagZoom
28+ :: forall tag sOuter sInner m a
29+ . Lens' sOuter sInner
30+ -> (forall z . Reifies z (ReifiedLens' sOuter sInner) => DispatchTagZoomT tag z m a)
31+ -> m a
32+tagZoom l m = reify (Lens l) (\(_ :: Proxy z) -> runDispatchT (m @z))
33+
34+instance ( MonadState tag sOuter m
35+ , Reifies z (ReifiedLens' sOuter sInner)
36+ ) => MonadState tag sInner (DispatchTagZoomT tag z m) where
37+ state t = dispatchT . state t . l
38+ where
39+ Lens l = reflect (Proxy :: Proxy z)
ether.cabaldeleted−237
@@ -1,237 +0,0 @@
1−cabal-version: 2.2
2−name: ether
3−version: 0.5.2.0
4−synopsis: Monad transformers and classes
5−description: Lib
6−license: BSD-3-Clause
7−-- ^ unfortunately have to change this line due to the issue with cabal2nix
8−license-file: LICENSE
9−category: Control
10−author: Vladislav Zavialov
11−maintainer: Vladislav Zavialov <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−extra-source-files: CHANGELOG.md
16−
17−source-repository head
18−
19− type: git
20− location: git@github.com:int-index/ether.git
21−
22−
23−flag disable-tup-instances
24−
25− description:
26− Disable auto-generated 'HasLens' instances for tuples. The reason one
27− might want to do this is to reduce the size of .hi-files, as well as the
28− time and memory GHC needs to build Ether. To recover flattening with
29− tuples, use 'Ether.Internal.makeTupleInstancesHasLens' at specific tuple
30− sizes you need in your application.
31−
32− This is a build-time performance hack, enable this flag at your own risk.
33−
34− default: False
35− manual: True
36−
37−library
38−
39− exposed-modules:
40− Ether
41− Ether.Reader
42− Ether.State
43− Ether.Writer
44− Ether.Except
45− Ether.TaggedTrans
46− Ether.TagDispatch
47− Ether.Internal
48−
49− other-modules:
50− Ether.Internal.Tags
51− Ether.Internal.HasLens
52− Ether.Internal.TH_Utils
53− Ether.Internal.TH_TupleInstances
54− Ether.Internal.TupleInstances
55−
56− build-depends:
57− base >=4.9 && <4.13,
58− transformers >=0.5.2.0,
59− transformers-lift >=0.2.0.1,
60− mtl >=2.2.2,
61− mmorph >=1.0.4,
62− monad-control >=1.0.0.4,
63− transformers-base >=0.4.4,
64− writer-cps-mtl >= 0.1.1.4,
65− exceptions >=0.8,
66− template-haskell >=2.11,
67− tagged >=0.8.5,
68− reflection >=2.1
69−
70− default-language:
71− Haskell2010
72−
73− default-extensions:
74− AllowAmbiguousTypes
75− ConstraintKinds
76− DataKinds
77− DeriveGeneric
78− EmptyDataDecls
79− FlexibleContexts
80− FlexibleInstances
81− FunctionalDependencies
82− GADTs
83− GeneralizedNewtypeDeriving
84− PartialTypeSignatures
85− PolyKinds
86− ScopedTypeVariables
87− RankNTypes
88− TemplateHaskell
89− TupleSections
90− TypeApplications
91− TypeFamilies
92− TypeInType
93− TypeOperators
94− TypeSynonymInstances
95− UndecidableInstances
96− UndecidableSuperClasses
97−
98− hs-source-dirs:
99− src
100−
101− ghc-options:
102− -Wall -O2
103−
104− if flag(disable-tup-instances)
105− cpp-options: -DDISABLE_TUP_INSTANCES
106−
107−test-suite regression
108−
109− build-depends:
110− base >=4.9 && <4.13,
111− transformers >=0.4.2,
112− mtl >=2.2.1,
113− tasty >=0.10,
114− tasty-quickcheck >=0.8,
115− QuickCheck >=2.8,
116− ghc-prim >=0.3,
117− lens >=4.14,
118− ether
119−
120− main-is:
121− Regression.hs
122−
123− other-modules:
124− TupleInstances
125− Regression.T1
126− Regression.T2
127− Regression.T3
128− Regression.T4
129− Regression.T5
130− Regression.T6
131− Regression.T7
132− Regression.T8
133− Regression.T9
134− Regression.T10
135− Regression.T11
136− Regression.T12
137−
138− type:
139− exitcode-stdio-1.0
140−
141− hs-source-dirs:
142− test
143−
144− default-language:
145− Haskell2010
146−
147− default-extensions:
148− AllowAmbiguousTypes
149− ConstraintKinds
150− DataKinds
151− DeriveGeneric
152− EmptyDataDecls
153− FlexibleContexts
154− FlexibleInstances
155− FunctionalDependencies
156− GADTs
157− GeneralizedNewtypeDeriving
158− PartialTypeSignatures
159− PolyKinds
160− ScopedTypeVariables
161− RankNTypes
162− TemplateHaskell
163− TupleSections
164− TypeApplications
165− TypeFamilies
166− TypeInType
167− TypeOperators
168− TypeSynonymInstances
169− UndecidableInstances
170− UndecidableSuperClasses
171−
172− ghc-options:
173− -Wall -fno-warn-missing-signatures
174−
175− if flag(disable-tup-instances)
176− cpp-options: -DDISABLE_TUP_INSTANCES
177−
178−
179−benchmark bench
180−
181− build-depends:
182− base >=4.9 && <4.13,
183− mtl >=2.2.1,
184− transformers >=0.4.2,
185− criterion >=1.1,
186− deepseq >=1.4,
187− lens >=4.14,
188− ether
189−
190− main-is:
191− Bench.hs
192−
193− other-modules:
194− TupleInstances
195−
196− type:
197− exitcode-stdio-1.0
198−
199− hs-source-dirs:
200− bench
201−
202− default-language:
203− Haskell2010
204−
205− default-extensions:
206− AllowAmbiguousTypes
207− ConstraintKinds
208− DataKinds
209− DeriveGeneric
210− EmptyDataDecls
211− FlexibleContexts
212− FlexibleInstances
213− FunctionalDependencies
214− GADTs
215− GeneralizedNewtypeDeriving
216− PartialTypeSignatures
217− PolyKinds
218− ScopedTypeVariables
219− RankNTypes
220− TemplateHaskell
221− TupleSections
222− TypeApplications
223− TypeFamilies
224− TypeInType
225− TypeOperators
226− TypeSynonymInstances
227− UndecidableInstances
228− UndecidableSuperClasses
229−
230− ghc-options:
231− -Wall -O2
232−
233− ghc-prof-options:
234− -fprof-auto
235−
236− if flag(disable-tup-instances)
237− cpp-options: -DDISABLE_TUP_INSTANCES
CHANGELOG.md → ether/CHANGELOG.mdrenamed+3−17
@@ -1,25 +1,11 @@
1−0.5.1.0
2−-------
3−
4−* Disable `HasLens` for tuples via cabal flag.
5−
60.5.0.0
10.5.0.0
7-------
2-------
8
3
9−* Support only GHC 8.0 and higher.
4+* Support GHC 8.0 only.
10−* Use the `TypeApplications` extension to get rid of `Proxy`.
5+* Utilize the `TypeApplications` extension.
11* Remove `Control.Ether.TH`.
6* Remove `Control.Ether.TH`.
12−* Remove `Control.Ether.Abbr`.
7+* Use `Proxy#` in class methods.
13−* Unify `Dispatch` and `TaggedTrans`.
14−* Better `MonadBase` and `MonadBaseControl` instances.
15−* Add flattening for `ReaderT` and `StateT`.
16−* Add zooming for `MonadState`.
17−* Simpler module structure.
18−
19−0.4.1.0
20−-------
21
8
22−* Export DispatchT newtype constructor.
23
9
240.4.0.0
100.4.0.0
25-------
11-------
ether/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2015, 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.
ether/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
ether/ether.cabalnew file+87
@@ -0,0 +1,87 @@
1+name: ether
2+version: 0.5.0.0
3+synopsis: Monad transformers and classes
4+description:
5+ Ether is a Haskell library that extends @mtl@ and @transformers@ with
6+ tagged monad transformers and classes in a compatible way.
7+
8+ Introduction <https://int-index.github.io/ether/>
9+
10+category: Control
11+license: BSD3
12+license-file: LICENSE
13+author: Index Int
14+maintainer: Index Int <vlad.z.4096@gmail.com>
15+homepage: https://int-index.github.io/ether/
16+bug-reports: https://github.com/int-index/ether/issues
17+build-type: Simple
18+cabal-version: >=1.18
19+extra-source-files: CHANGELOG.md
20+
21+source-repository head
22+
23+ type: git
24+ location: git@github.com:int-index/ether.git
25+
26+
27+library
28+
29+ exposed-modules: Control.Ether.Abbr
30+ Control.Ether.Implicit.Abbr
31+ Control.Monad.Trans.Ether.Reader
32+ Control.Monad.Trans.Ether.Writer
33+ Control.Monad.Trans.Ether.State
34+ Control.Monad.Trans.Ether.State.Lazy
35+ Control.Monad.Trans.Ether.State.Strict
36+ Control.Monad.Trans.Ether.Except
37+ Control.Monad.Trans.Ether.Dispatch
38+ Control.Monad.Trans.Ether.Tagged
39+ Control.Monad.Ether
40+ Control.Monad.Ether.Reader
41+ Control.Monad.Ether.Reader.Class
42+ Control.Monad.Ether.Writer
43+ Control.Monad.Ether.Writer.Class
44+ Control.Monad.Ether.State
45+ Control.Monad.Ether.State.Class
46+ Control.Monad.Ether.State.Lazy
47+ Control.Monad.Ether.State.Strict
48+ Control.Monad.Ether.Except
49+ Control.Monad.Ether.Except.Class
50+ Control.Monad.Ether.Implicit
51+ Control.Monad.Ether.Implicit.Reader
52+ Control.Monad.Ether.Implicit.Writer
53+ Control.Monad.Ether.Implicit.State
54+ Control.Monad.Ether.Implicit.State.Lazy
55+ Control.Monad.Ether.Implicit.State.Strict
56+ Control.Monad.Ether.Implicit.Except
57+
58+ other-modules: Control.Monad.Ether.State.Common
59+
60+ build-depends: base >=4.9 && <4.10
61+ , transformers >=0.4.2
62+ , transformers-lift >=0.1.0.1
63+ , mtl >=2.2.1
64+ , mmorph >=1.0.4
65+ , monad-control >=1.0.0.4
66+ , transformers-base >=0.4.4
67+ , exceptions >=0.8
68+ , ghc-prim >=0.3
69+
70+ default-language: Haskell2010
71+ default-extensions: PolyKinds
72+ ScopedTypeVariables
73+ FunctionalDependencies
74+ TypeApplications
75+ other-extensions: ConstraintKinds
76+ DataKinds
77+ DefaultSignatures
78+ DeriveGeneric
79+ FlexibleInstances
80+ GeneralizedNewtypeDeriving
81+ MagicHash
82+ TypeFamilies
83+ TypeOperators
84+ UndecidableInstances
85+
86+ hs-source-dirs: src
87+ ghc-options: -Wall
ether/src/Control/Ether/Abbr.hsnew file+60
@@ -0,0 +1,60 @@
1+{-# LANGUAGE EmptyDataDecls #-}
2+{-# LANGUAGE TypeOperators #-}
3+{-# LANGUAGE ConstraintKinds #-}
4+{-# LANGUAGE DataKinds #-}
5+{-# LANGUAGE TypeFamilies #-}
6+
7+-- | Abbreviations for constraints.
8+
9+module Control.Ether.Abbr
10+ ( type (-->)
11+ , type (<--)
12+ , type (<->)
13+ , type (-!-)
14+ , Ether
15+ , ReifyAbbr
16+ ) where
17+
18+import GHC.Exts (Constraint)
19+
20+import Control.Monad.Ether
21+
22+-- | Turns an abbreviation into an actual constraint.
23+type family ReifyAbbr (abbr :: *) (m :: * -> *) :: Constraint
24+
25+-- | Denotes 'MonadReader'. The mnemonic is that you read values of type @r@
26+-- from the reader environment tagged by @tag@, thus the arrows points
27+-- from @tag@ to @r@.
28+data tag --> r
29+type instance ReifyAbbr (tag --> r) m = MonadReader tag r m
30+
31+-- | Denotes 'MonadWriter'. The mnemonic is that you write values of type @w@
32+-- to the writer accumulator tagged by @tag@, thus the arrows points
33+-- from @w@ to @tag@.
34+data tag <-- w
35+type instance ReifyAbbr (tag <-- w) m = MonadWriter tag w m
36+
37+-- | Denotes 'MonadState'. The mnemonic is that you can both read from and
38+-- write into the state, thus the arrow points in both directions.
39+data tag <-> s
40+type instance ReifyAbbr (tag <-> s) m = MonadState tag s m
41+
42+-- | Denotes 'MonadExcept'.
43+data tag -!- e
44+type instance ReifyAbbr (tag -!- e) m = MonadExcept tag e m
45+
46+-- | Reify a list of constraint abbreviations.
47+--
48+-- > f :: Ether '[Foo --> r, Bar <-- w, Baz <-> s, Quux -!- e] m => m a
49+--
50+-- expands into
51+--
52+-- > f :: ( MonadReader Foo r m
53+-- > , MonadWriter Bar w m
54+-- > , MonadState Baz s m
55+-- > , MonadExcept Quux e m
56+-- > ) => m a
57+
58+type family Ether (abbrs :: [*]) m :: Constraint where
59+ Ether '[] m = ()
60+ Ether (abbr ': abbrs) m = (ReifyAbbr abbr m, Ether abbrs m)
ether/src/Control/Ether/Implicit/Abbr.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE TypeFamilies #-}
2+
3+-- | See "Control.Ether.Abbr".
4+
5+module Control.Ether.Implicit.Abbr (R, W, S, E) where
6+
7+import Control.Ether.Abbr (ReifyAbbr)
8+import Control.Monad.Ether.Implicit
9+
10+-- | Denotes 'MonadReader'.
11+data R r
12+type instance ReifyAbbr (R r) m = MonadReader r m
13+
14+-- | Denotes 'MonadWriter'.
15+data W w
16+type instance ReifyAbbr (W w) m = MonadWriter w m
17+
18+-- | Denotes 'MonadState'.
19+data S s
20+type instance ReifyAbbr (S s) m = MonadState s m
21+
22+-- | Denotes 'MonadExcept'.
23+data E e
24+type instance ReifyAbbr (E e) m = MonadExcept e m
25+
ether/src/Control/Monad/Ether.hsnew file+13
@@ -0,0 +1,13 @@
1+
2+-- | This module provides convenience exports of all
3+-- tagged monad classes from Ether.
4+
5+module Control.Monad.Ether (module X) where
6+
7+import Control.Monad as X
8+import Control.Monad.Fix as X
9+import Control.Monad.Ether.Reader as X
10+import Control.Monad.Ether.Writer as X
11+import Control.Monad.Ether.State as X
12+import Control.Monad.Ether.Except as X
13+import Control.Monad.Trans.Ether.Dispatch as X (tagAttach, tagReplace)
ether/src/Control/Monad/Ether/Except.hsnew file+45
@@ -0,0 +1,45 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
3+
4+-- | See "Control.Monad.Except".
5+
6+module Control.Monad.Ether.Except
7+ (
8+ -- * MonadExcept class
9+ MonadExcept
10+ , throw
11+ , catch
12+ -- * The Except monad
13+ , Except
14+ , runExcept
15+ -- * The ExceptT monad transformer
16+ , ExceptT
17+ , exceptT
18+ , runExceptT
19+ -- * Handle functions
20+ , handleT
21+ , handle
22+ ) where
23+
24+import GHC.Prim (Proxy#, proxy#)
25+import Control.Monad.Ether.Except.Class (MonadExcept)
26+import qualified Control.Monad.Ether.Except.Class as C
27+import Control.Monad.Trans.Ether.Except hiding (throw, catch)
28+import Data.Functor.Identity (Identity(..))
29+
30+-- | Is used within a monadic computation to begin exception processing.
31+throw :: forall tag e m a . MonadExcept tag e m => e -> m a
32+throw = C.throw (proxy# :: Proxy# tag)
33+
34+-- | A handler function to handle previous exceptions and return to
35+-- normal execution.
36+catch :: forall tag e m a . MonadExcept tag e m => m a -> (e -> m a) -> m a
37+catch = C.catch (proxy# :: Proxy# tag)
38+
39+-- | Runs an 'Except' and handles the exception with the given function.
40+handle :: forall tag e a . (e -> a) -> Except tag e a -> a
41+handle h m = runIdentity (handleT @tag h m)
42+
43+-- | Runs an 'ExceptT' and handles the exception with the given function.
44+handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
45+handleT h m = fmap (either h id) (runExceptT @tag m)
ether/src/Control/Monad/Ether/Except/Class.hsnew file+36
@@ -0,0 +1,36 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE UndecidableInstances #-}
3+{-# LANGUAGE TypeFamilies #-}
4+{-# LANGUAGE MagicHash #-}
5+
6+-- | See "Control.Monad.Except".
7+
8+module Control.Monad.Ether.Except.Class
9+ ( MonadExcept(..)
10+ ) where
11+
12+import GHC.Prim (Proxy#)
13+import qualified Control.Monad.Trans.Ether.Except as E
14+import qualified Control.Monad.Trans.Lift.Catch as Lift
15+
16+-- | See 'Control.Monad.Except.MonadError'.
17+class Monad m => MonadExcept tag e m | m tag -> e where
18+
19+ -- | Is used within a monadic computation to begin exception processing.
20+ throw :: Proxy# tag -> e -> m a
21+
22+ -- | A handler function to handle previous exceptions and return to
23+ -- normal execution.
24+ catch :: Proxy# tag -> m a -> (e -> m a) -> m a
25+
26+instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
27+ throw _ = E.throw @tag
28+ catch _ = E.catch @tag
29+
30+instance {-# OVERLAPPABLE #-}
31+ ( Lift.LiftCatch t
32+ , Monad (t m)
33+ , MonadExcept tag e m
34+ ) => MonadExcept tag e (t m) where
35+ throw t = Lift.lift . throw t
36+ catch t = Lift.liftCatch (catch t)
ether/src/Control/Monad/Ether/Implicit.hsnew file+13
@@ -0,0 +1,13 @@
1+
2+-- | This module provides convenience exports of all
3+-- implicitly tagged monad classes from Ether.
4+
5+module Control.Monad.Ether.Implicit (module X) where
6+
7+import Control.Monad as X
8+import Control.Monad.Fix as X
9+import Control.Monad.Ether.Implicit.Reader as X
10+import Control.Monad.Ether.Implicit.Writer as X
11+import Control.Monad.Ether.Implicit.State as X
12+import Control.Monad.Ether.Implicit.Except as X
13+import Control.Monad.Trans.Ether.Dispatch as X
ether/src/Control/Monad/Ether/Implicit/Except.hsnew file+60
@@ -0,0 +1,60 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+
3+-- | See "Control.Monad.Ether.Except".
4+
5+module Control.Monad.Ether.Implicit.Except
6+ (
7+ -- * MonadExcept class
8+ MonadExcept
9+ , throw
10+ , catch
11+ -- * The Except monad
12+ , Except
13+ , runExcept
14+ -- * The ExceptT monad transformer
15+ , ExceptT
16+ , exceptT
17+ , runExceptT
18+ -- * Handle functions
19+ , handle
20+ , handleT
21+ ) where
22+
23+import qualified Control.Monad.Ether.Except as A
24+
25+-- | See 'Control.Monad.Ether.Except.MonadExcept'.
26+type MonadExcept e = A.MonadExcept e e
27+
28+-- | See 'Control.Monad.Ether.Except.throw'.
29+throw :: forall e m a . MonadExcept e m => e -> m a
30+throw = A.throw @e
31+
32+-- | See 'Control.Monad.Ether.Except.catch'.
33+catch :: forall e m a . MonadExcept e m => m a -> (e -> m a) -> m a
34+catch = A.catch @e
35+
36+-- | See 'Control.Monad.Ether.Except.Except'.
37+type Except e = A.Except e e
38+
39+-- | See 'Control.Monad.Ether.Except.runExcept'.
40+runExcept :: Except e a -> Either e a
41+runExcept = A.runExcept
42+
43+-- | See 'Control.Monad.Ether.Except.ExceptT'.
44+type ExceptT e = A.ExceptT e e
45+
46+-- | See 'Control.Monad.Ether.Except.exceptT'.
47+exceptT :: m (Either e a) -> ExceptT e m a
48+exceptT = A.exceptT
49+
50+-- | See 'Control.Monad.Ether.Except.runExceptT'.
51+runExceptT :: ExceptT e m a -> m (Either e a)
52+runExceptT = A.runExceptT
53+
54+-- | See 'Control.Monad.Ether.Except.handle'.
55+handle :: (e -> a) -> Except e a -> a
56+handle = A.handle
57+
58+-- | See 'Control.Monad.Ether.Except.handleT'.
59+handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a
60+handleT = A.handleT
ether/src/Control/Monad/Ether/Implicit/Reader.hsnew file+59
@@ -0,0 +1,59 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+
3+-- | See "Control.Monad.Ether.Reader".
4+
5+module Control.Monad.Ether.Implicit.Reader
6+ (
7+ -- * MonadReader class
8+ MonadReader
9+ , local
10+ , ask
11+ , reader
12+ , asks
13+ -- * The Reader monad
14+ , Reader
15+ , runReader
16+ -- * The ReaderT monad transformer
17+ , ReaderT
18+ , readerT
19+ , runReaderT
20+ ) where
21+
22+import qualified Control.Monad.Ether.Reader as A
23+
24+-- | See 'Control.Monad.Ether.Reader.ReaderT'.
25+type ReaderT r = A.ReaderT r r
26+
27+-- | See 'Control.Monad.Ether.Reader.readerT'.
28+readerT :: (r -> m a) -> ReaderT r m a
29+readerT = A.readerT
30+
31+-- | See 'Control.Monad.Ether.Reader.runReaderT'.
32+runReaderT :: ReaderT r m a -> r -> m a
33+runReaderT = A.runReaderT
34+
35+-- | See 'Control.Monad.Ether.Reader.Reader'.
36+type Reader r = A.Reader r r
37+
38+-- | See 'Control.Monad.Ether.Reader.runReader'.
39+runReader :: Reader r a -> r -> a
40+runReader = A.runReader
41+
42+-- | See 'Control.Monad.Ether.Reader.MonadReader'.
43+type MonadReader r = A.MonadReader r r
44+
45+-- | See 'Control.Monad.Ether.Reader.local'.
46+local :: forall r m a . MonadReader r m => (r -> r) -> m a -> m a
47+local = A.local @r
48+
49+-- | See 'Control.Monad.Ether.Reader.ask'.
50+ask :: forall r m . MonadReader r m => m r
51+ask = A.ask @r
52+
53+-- | See 'Control.Monad.Ether.Reader.reader'.
54+reader :: forall r m a . MonadReader r m => (r -> a) -> m a
55+reader = A.reader @r
56+
57+-- | See 'Control.Monad.Ether.Reader.asks'.
58+asks :: forall r m a . MonadReader r m => (r -> a) -> m a
59+asks = A.asks @r
ether/src/Control/Monad/Ether/Implicit/State.hsnew file+8
@@ -0,0 +1,8 @@
1+
2+-- | See "Control.Monad.Ether.State".
3+
4+module Control.Monad.Ether.Implicit.State
5+ ( module Control.Monad.Ether.Implicit.State.Lazy
6+ ) where
7+
8+import Control.Monad.Ether.Implicit.State.Lazy
ether/src/Control/Monad/Ether/Implicit/State/Lazy.hsnew file+84
@@ -0,0 +1,84 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+
3+-- | See "Control.Monad.Ether.State.Lazy".
4+
5+module Control.Monad.Ether.Implicit.State.Lazy
6+ (
7+ -- * MonadState class
8+ MonadState
9+ , get
10+ , put
11+ , state
12+ , modify
13+ , gets
14+ -- * The State monad
15+ , State
16+ , runState
17+ , evalState
18+ , execState
19+ -- * The StateT monad transformer
20+ , StateT
21+ , stateT
22+ , runStateT
23+ , evalStateT
24+ , execStateT
25+ ) where
26+
27+import qualified Control.Monad.Ether.State.Lazy as A
28+
29+-- | See 'Control.Monad.Ether.State.Lazy.StateT'.
30+type StateT s = A.StateT s s
31+
32+-- | See 'Control.Monad.Ether.State.Lazy.stateT'.
33+stateT :: (s -> m (a, s)) -> StateT s m a
34+stateT = A.stateT
35+
36+-- | See 'Control.Monad.Ether.State.Lazy.runStateT'.
37+runStateT :: StateT s m a -> s -> m (a, s)
38+runStateT = A.runStateT
39+
40+-- | See 'Control.Monad.Ether.State.Lazy.runState'.
41+runState :: State s a -> s -> (a, s)
42+runState = A.runState
43+
44+-- | See 'Control.Monad.Ether.State.Lazy.evalStateT'.
45+evalStateT :: Monad m => StateT s m a -> s -> m a
46+evalStateT = A.evalStateT
47+
48+-- | See 'Control.Monad.Ether.State.Lazy.State'.
49+type State s = A.State s s
50+
51+-- | See 'Control.Monad.Ether.State.Lazy.evalState'.
52+evalState :: State s a -> s -> a
53+evalState = A.evalState
54+
55+-- | See 'Control.Monad.Ether.State.Lazy.execStateT'.
56+execStateT :: Monad m => StateT s m a -> s -> m s
57+execStateT = A.execStateT
58+
59+-- | See 'Control.Monad.Ether.State.Lazy.execState'.
60+execState :: State s a -> s -> s
61+execState = A.execState
62+
63+-- | See 'Control.Monad.Ether.State.Lazy.MonadState'.
64+type MonadState s = A.MonadState s s
65+
66+-- | See 'Control.Monad.Ether.State.Lazy.get'.
67+get :: forall s m . MonadState s m => m s
68+get = A.get @s
69+
70+-- | See 'Control.Monad.Ether.State.Lazy.gets'.
71+gets :: forall s m a . MonadState s m => (s -> a) -> m a
72+gets = A.gets @s
73+
74+-- | See 'Control.Monad.Ether.State.Lazy.put'.
75+put :: forall s m . MonadState s m => s -> m ()
76+put = A.put @s
77+
78+-- | See 'Control.Monad.Ether.State.Lazy.state'.
79+state :: forall s m a . MonadState s m => (s -> (a, s)) -> m a
80+state = A.state @s
81+
82+-- | See 'Control.Monad.Ether.State.Lazy.modify'.
83+modify :: forall s m . MonadState s m => (s -> s) -> m ()
84+modify = A.modify @s
ether/src/Control/Monad/Ether/Implicit/State/Strict.hsnew file+84
@@ -0,0 +1,84 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+
3+-- | See "Control.Monad.Ether.State.Strict".
4+
5+module Control.Monad.Ether.Implicit.State.Strict
6+ (
7+ -- * MonadState class
8+ MonadState
9+ , get
10+ , put
11+ , state
12+ , modify
13+ , gets
14+ -- * The State monad
15+ , State
16+ , runState
17+ , evalState
18+ , execState
19+ -- * The StateT monad transformer
20+ , StateT
21+ , stateT
22+ , runStateT
23+ , evalStateT
24+ , execStateT
25+ ) where
26+
27+import qualified Control.Monad.Ether.State.Strict as A
28+
29+-- | See 'Control.Monad.Ether.State.Strict.StateT'.
30+type StateT s = A.StateT s s
31+
32+-- | See 'Control.Monad.Ether.State.Strict.stateT'.
33+stateT :: (s -> m (a, s)) -> StateT s m a
34+stateT = A.stateT
35+
36+-- | See 'Control.Monad.Ether.State.Strict.runStateT'.
37+runStateT :: StateT s m a -> s -> m (a, s)
38+runStateT = A.runStateT
39+
40+-- | See 'Control.Monad.Ether.State.Strict.runState'.
41+runState :: State s a -> s -> (a, s)
42+runState = A.runState
43+
44+-- | See 'Control.Monad.Ether.State.Strict.evalStateT'.
45+evalStateT :: Monad m => StateT s m a -> s -> m a
46+evalStateT = A.evalStateT
47+
48+-- | See 'Control.Monad.Ether.State.Strict.State'.
49+type State s = A.State s s
50+
51+-- | See 'Control.Monad.Ether.State.Strict.evalState'.
52+evalState :: State s a -> s -> a
53+evalState = A.evalState
54+
55+-- | See 'Control.Monad.Ether.State.Strict.execStateT'.
56+execStateT :: Monad m => StateT s m a -> s -> m s
57+execStateT = A.execStateT
58+
59+-- | See 'Control.Monad.Ether.State.Strict.execState'.
60+execState :: State s a -> s -> s
61+execState = A.execState
62+
63+-- | See 'Control.Monad.Ether.State.Strict.MonadState'.
64+type MonadState s = A.MonadState s s
65+
66+-- | See 'Control.Monad.Ether.State.Strict.get'.
67+get :: forall s m . MonadState s m => m s
68+get = A.get @s
69+
70+-- | See 'Control.Monad.Ether.State.Strict.gets'.
71+gets :: forall s m a . MonadState s m => (s -> a) -> m a
72+gets = A.gets @s
73+
74+-- | See 'Control.Monad.Ether.State.Strict.put'.
75+put :: forall s m . MonadState s m => s -> m ()
76+put = A.put @s
77+
78+-- | See 'Control.Monad.Ether.State.Strict.state'.
79+state :: forall s m a . MonadState s m => (s -> (a, s)) -> m a
80+state = A.state @s
81+
82+-- | See 'Control.Monad.Ether.State.Strict.modify'.
83+modify :: forall s m . MonadState s m => (s -> s) -> m ()
84+modify = A.modify @s
ether/src/Control/Monad/Ether/Implicit/Writer.hsnew file+79
@@ -0,0 +1,79 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+
3+-- | See "Control.Monad.Ether.Writer".
4+
5+module Control.Monad.Ether.Implicit.Writer
6+ (
7+ -- * MonadWriter class
8+ MonadWriter
9+ , writer
10+ , tell
11+ , listen
12+ , pass
13+ , listens
14+ , censor
15+ -- * The Writer monad
16+ , Writer
17+ , runWriter
18+ , execWriter
19+ -- * The WriterT monad transformer
20+ , WriterT
21+ , writerT
22+ , runWriterT
23+ , execWriterT
24+ ) where
25+
26+import qualified Control.Monad.Ether.Writer as A
27+
28+-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
29+type MonadWriter w = A.MonadWriter w w
30+
31+-- | See 'Control.Monad.Ether.Writer.writer'.
32+writer :: forall w m a . MonadWriter w m => (a, w) -> m a
33+writer = A.writer @w
34+
35+-- | See 'Control.Monad.Ether.Writer.tell'.
36+tell :: forall w m . MonadWriter w m => w -> m ()
37+tell = A.tell @w
38+
39+-- | See 'Control.Monad.Ether.Writer.listen'.
40+listen :: forall w m a . MonadWriter w m => m a -> m (a, w)
41+listen = A.listen @w
42+
43+-- | See 'Control.Monad.Ether.Writer.pass'.
44+pass :: forall w m a . MonadWriter w m => m (a, w -> w) -> m a
45+pass = A.pass @w
46+
47+-- | See 'Control.Monad.Ether.Writer.listens'.
48+listens :: forall w m a b . MonadWriter w m => (w -> b) -> m a -> m (a, b)
49+listens = A.listens @w
50+
51+-- | See 'Control.Monad.Ether.Writer.censor'.
52+censor :: forall w m a . MonadWriter w m => (w -> w) -> m a -> m a
53+censor = A.censor @w
54+
55+-- | See 'Control.Monad.Ether.Writer.Writer'.
56+type Writer w = A.Writer w w
57+
58+-- | See 'Control.Monad.Ether.Writer.runWriter'.
59+runWriter :: Writer w a -> (a, w)
60+runWriter = A.runWriter
61+
62+-- | See 'Control.Monad.Ether.Writer.execWriter'.
63+execWriter :: Writer w a -> w
64+execWriter = A.execWriter
65+
66+-- | See 'Control.Monad.Ether.Writer.WriterT'.
67+type WriterT w = A.WriterT w w
68+
69+-- | See 'Control.Monad.Ether.Writer.writerT'.
70+writerT :: m (a, w) -> WriterT w m a
71+writerT = A.writerT
72+
73+-- | See 'Control.Monad.Ether.Writer.runWriterT'.
74+runWriterT :: WriterT w m a -> m (a, w)
75+runWriterT = A.runWriterT
76+
77+-- | See 'Control.Monad.Ether.Writer.execWriterT'.
78+execWriterT :: Monad m => WriterT w m a -> m w
79+execWriterT = A.execWriterT
ether/src/Control/Monad/Ether/Reader.hsnew file+59
@@ -0,0 +1,59 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
3+
4+-- | See "Control.Monad.Reader".
5+
6+module Control.Monad.Ether.Reader
7+ (
8+ -- * MonadReader class
9+ MonadReader
10+ , ask
11+ , local
12+ , reader
13+ , asks
14+ -- * The Reader monad
15+ , Reader
16+ , runReader
17+ -- * The ReaderT monad transformer
18+ , ReaderT
19+ , readerT
20+ , runReaderT
21+ ) where
22+
23+import GHC.Prim (Proxy#, proxy#)
24+import Control.Monad.Ether.Reader.Class (MonadReader)
25+import qualified Control.Monad.Ether.Reader.Class as C
26+import Control.Monad.Trans.Ether.Reader hiding (reader, ask, local)
27+
28+-- | Retrieves the monad environment.
29+ask :: forall tag r m . MonadReader tag r m => m r
30+ask = C.ask (proxy# :: Proxy# tag)
31+
32+-- | Executes a computation in a modified environment.
33+local
34+ :: forall tag r m a
35+ . MonadReader tag r m
36+ => (r -> r)
37+ -- ^ The function to modify the environment.
38+ -> m a
39+ -- ^ @Reader@ to run in the modified environment.
40+ -> m a
41+local = C.local (proxy# :: Proxy# tag)
42+
43+-- | Retrieves a function of the current environment.
44+reader
45+ :: forall tag r m a
46+ . MonadReader tag r m
47+ => (r -> a)
48+ -- ^ The selector function to apply to the environment.
49+ -> m a
50+reader = C.reader (proxy# :: Proxy# tag)
51+
52+-- | Retrieves a function of the current environment.
53+asks
54+ :: forall tag r m a
55+ . MonadReader tag r m
56+ => (r -> a)
57+ -- ^ The selector function to apply to the environment.
58+ -> m a
59+asks = C.reader (proxy# :: Proxy# tag)
ether/src/Control/Monad/Ether/Reader/Class.hsnew file+53
@@ -0,0 +1,53 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE UndecidableInstances #-}
3+{-# LANGUAGE TypeFamilies #-}
4+{-# LANGUAGE MagicHash #-}
5+
6+-- | See "Control.Monad.Reader.Class".
7+
8+module Control.Monad.Ether.Reader.Class
9+ ( MonadReader(..)
10+ ) where
11+
12+import GHC.Prim (Proxy#)
13+import qualified Control.Monad.Trans.Ether.Reader as R
14+import qualified Control.Monad.Trans.Lift.Local as Lift
15+
16+-- | See 'Control.Monad.Reader.MonadReader'.
17+class Monad m => MonadReader tag r m | m tag -> r where
18+
19+ {-# MINIMAL (ask | reader), local #-}
20+
21+ -- | Retrieves the monad environment.
22+ ask :: Proxy# tag -> m r
23+ ask t = reader t id
24+
25+ -- | Executes a computation in a modified environment.
26+ local
27+ :: Proxy# tag
28+ -> (r -> r)
29+ -- ^ The function to modify the environment.
30+ -> m a
31+ -- ^ @Reader@ to run in the modified environment.
32+ -> m a
33+
34+ -- | Retrieves a function of the current environment.
35+ reader
36+ :: Proxy# tag
37+ -> (r -> a)
38+ -- ^ The selector function to apply to the environment.
39+ -> m a
40+ reader t f = fmap f (ask t)
41+
42+instance (Monad m, r ~ r') => MonadReader tag r (R.ReaderT tag r' m) where
43+ ask _ = R.ask @tag
44+ local _ = R.local @tag
45+ reader _ = R.reader @tag
46+
47+instance {-# OVERLAPPABLE #-}
48+ ( Lift.LiftLocal t
49+ , Monad (t m)
50+ , MonadReader tag r m
51+ ) => MonadReader tag r (t m) where
52+ ask t = Lift.lift (ask t)
53+ local t = Lift.liftLocal (ask t) (local t)
ether/src/Control/Monad/Ether/State.hsnew file+8
@@ -0,0 +1,8 @@
1+
2+-- | See "Control.Monad.State".
3+
4+module Control.Monad.Ether.State
5+ ( module Control.Monad.Ether.State.Lazy
6+ ) where
7+
8+import Control.Monad.Ether.State.Lazy
ether/src/Control/Monad/Ether/State/Class.hsnew file+55
@@ -0,0 +1,55 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE UndecidableInstances #-}
3+{-# LANGUAGE TypeFamilies #-}
4+{-# LANGUAGE MagicHash #-}
5+
6+-- | See "Control.Monad.State.Class".
7+
8+module Control.Monad.Ether.State.Class
9+ ( MonadState(..)
10+ ) where
11+
12+import GHC.Prim (Proxy#)
13+import qualified Control.Monad.Trans.Ether.State.Lazy as S.L
14+import qualified Control.Monad.Trans.Ether.State.Strict as S.S
15+import qualified Control.Monad.Trans as Lift
16+
17+-- | See 'Control.Monad.State.MonadState'.
18+class Monad m => MonadState tag s m | m tag -> s where
19+
20+ {-# MINIMAL state | get, put #-}
21+
22+ -- | Return the state from the internals of the monad.
23+ get :: Proxy# tag -> m s
24+ get t = state t (\s -> (s, s))
25+
26+ -- | Replace the state inside the monad.
27+ put :: Proxy# tag -> s -> m ()
28+ put t s = state t (\_ -> ((), s))
29+
30+ -- | Embed a simple state action into the monad.
31+ state :: Proxy# tag -> (s -> (a, s)) -> m a
32+ state t f = do
33+ s <- get t
34+ let ~(a, s') = f s
35+ put t s'
36+ return a
37+
38+instance (Monad m, s ~ s') => MonadState tag s (S.L.StateT tag s' m) where
39+ get _ = S.L.get @tag
40+ put _ = S.L.put @tag
41+ state _ = S.L.state @tag
42+
43+instance (Monad m, s ~ s') => MonadState tag s (S.S.StateT tag s' m) where
44+ get _ = S.S.get @tag
45+ put _ = S.S.put @tag
46+ state _ = S.S.state @tag
47+
48+instance {-# OVERLAPPABLE #-}
49+ ( Lift.MonadTrans t
50+ , Monad (t m)
51+ , MonadState tag s m
52+ ) => MonadState tag s (t m) where
53+ get t = Lift.lift (get t)
54+ put t = Lift.lift . put t
55+ state t = Lift.lift . state t
ether/src/Control/Monad/Ether/State/Common.hsnew file+35
@@ -0,0 +1,35 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
3+
4+module Control.Monad.Ether.State.Common
5+ ( MonadState
6+ , get
7+ , put
8+ , state
9+ , modify
10+ , gets
11+ ) where
12+
13+import GHC.Prim (Proxy#, proxy#)
14+import Control.Monad.Ether.State.Class (MonadState)
15+import qualified Control.Monad.Ether.State.Class as C
16+
17+-- | Return the state from the internals of the monad.
18+get :: forall tag s m . MonadState tag s m => m s
19+get = C.get (proxy# :: Proxy# tag)
20+
21+-- | Replace the state inside the monad.
22+put :: forall tag s m . MonadState tag s m => s -> m ()
23+put = C.put (proxy# :: Proxy# tag)
24+
25+-- | Embed a simple state action into the monad.
26+state :: forall tag s m a . MonadState tag s m => (s -> (a, s)) -> m a
27+state = C.state (proxy# :: Proxy# tag)
28+
29+-- | Modifies the state inside a state monad.
30+modify :: forall tag s m . MonadState tag s m => (s -> s) -> m ()
31+modify f = state @tag (\s -> ((), f s))
32+
33+-- | Gets specific component of the state, using a projection function supplied.
34+gets :: forall tag s m a . MonadState tag s m => (s -> a) -> m a
35+gets f = fmap f (get @tag)
ether/src/Control/Monad/Ether/State/Lazy.hsnew file+27
@@ -0,0 +1,27 @@
1+
2+-- | See "Control.Monad.State.Lazy".
3+
4+module Control.Monad.Ether.State.Lazy
5+ (
6+ -- * MonadState class
7+ MonadState
8+ , get
9+ , put
10+ , state
11+ , modify
12+ , gets
13+ -- * The State monad
14+ , State
15+ , runState
16+ , evalState
17+ , execState
18+ -- * The StateT monad transformer
19+ , StateT
20+ , stateT
21+ , runStateT
22+ , evalStateT
23+ , execStateT
24+ ) where
25+
26+import Control.Monad.Ether.State.Common
27+import Control.Monad.Trans.Ether.State.Lazy hiding (state, get, put)
ether/src/Control/Monad/Ether/State/Strict.hsnew file+27
@@ -0,0 +1,27 @@
1+
2+-- | See "Control.Monad.State.Strict".
3+
4+module Control.Monad.Ether.State.Strict
5+ (
6+ -- * MonadState class
7+ MonadState
8+ , get
9+ , put
10+ , state
11+ , modify
12+ , gets
13+ -- * The State monad
14+ , State
15+ , runState
16+ , evalState
17+ , execState
18+ -- * The StateT monad transformer
19+ , StateT
20+ , stateT
21+ , runStateT
22+ , evalStateT
23+ , execStateT
24+ ) where
25+
26+import Control.Monad.Ether.State.Common
27+import Control.Monad.Trans.Ether.State.Strict hiding (state, get, put)
ether/src/Control/Monad/Ether/Writer.hsnew file+61
@@ -0,0 +1,61 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
3+
4+-- | See "Control.Monad.Writer".
5+
6+module Control.Monad.Ether.Writer
7+ (
8+ -- * MonadWriter class
9+ MonadWriter
10+ , writer
11+ , tell
12+ , listen
13+ , pass
14+ , listens
15+ , censor
16+ -- * The Writer monad
17+ , Writer
18+ , runWriter
19+ , execWriter
20+ -- * The WriterT monad transformer
21+ , WriterT
22+ , writerT
23+ , runWriterT
24+ , execWriterT
25+ ) where
26+
27+import GHC.Prim (Proxy#, proxy#)
28+import Control.Monad.Ether.Writer.Class (MonadWriter)
29+import qualified Control.Monad.Ether.Writer.Class as C
30+import Control.Monad.Trans.Ether.Writer hiding (writer, tell, listen, pass)
31+
32+-- | Embed a simple writer action.
33+writer :: forall tag w m a . MonadWriter tag w m => (a, w) -> m a
34+writer = C.writer (proxy# :: Proxy# tag)
35+
36+-- | Append a value to the accumulator within the monad.
37+tell :: forall tag w m . MonadWriter tag w m => w -> m ()
38+tell = C.tell (proxy# :: Proxy# tag)
39+
40+-- | Execute an action and add its accumulator
41+-- to the value of the computation.
42+listen :: forall tag w m a . MonadWriter tag w m => m a -> m (a, w)
43+listen = C.listen (proxy# :: Proxy# tag)
44+
45+-- | Execute an action which returns a value and a function,
46+-- and return the value, applying the function to the accumulator.
47+pass :: forall tag w m a . MonadWriter tag w m => m (a, w -> w) -> m a
48+pass = C.pass (proxy# :: Proxy# tag)
49+
50+-- | Execute an action and add the result of applying the given function to
51+-- its accumulator to the value of the computation.
52+listens :: forall tag w m a b . MonadWriter tag w m => (w -> b) -> m a -> m (a, b)
53+listens f m = do
54+ ~(a, w) <- listen @tag m
55+ return (a, f w)
56+
57+-- | Execute an action and apply a function to its accumulator.
58+censor :: forall tag w m a . MonadWriter tag w m => (w -> w) -> m a -> m a
59+censor f m = pass @tag $ do
60+ a <- m
61+ return (a, f)
ether/src/Control/Monad/Ether/Writer/Class.hsnew file+56
@@ -0,0 +1,56 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE UndecidableInstances #-}
3+{-# LANGUAGE TypeFamilies #-}
4+{-# LANGUAGE MagicHash #-}
5+
6+-- | See "Control.Monad.Writer.Class".
7+
8+module Control.Monad.Ether.Writer.Class
9+ ( MonadWriter(..)
10+ ) where
11+
12+import GHC.Prim (Proxy#)
13+import qualified Control.Monad.Trans.Ether.Writer as W
14+import qualified Control.Monad.Trans.Lift.Listen as Lift
15+import qualified Control.Monad.Trans.Lift.Pass as Lift
16+
17+-- | See 'Control.Monad.Writer.MonadWriter'.
18+class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where
19+
20+ {-# MINIMAL (writer | tell), listen, pass #-}
21+
22+ -- | Embed a simple writer action.
23+ writer :: Proxy# tag -> (a, w) -> m a
24+ writer t ~(a, w) = do
25+ tell t w
26+ return a
27+
28+ -- | Append a value to the accumulator within the monad.
29+ tell :: Proxy# tag -> w -> m ()
30+ tell t w = writer t ((),w)
31+
32+ -- | Execute an action and add its accumulator
33+ -- to the value of the computation.
34+ listen :: Proxy# tag -> m a -> m (a, w)
35+
36+ -- | Execute an action which returns a value and a function,
37+ -- and return the value, applying the function to the accumulator.
38+ pass :: Proxy# tag -> m (a, w -> w) -> m a
39+
40+instance (Monoid w, Monad m, w ~ w') => MonadWriter tag w (W.WriterT tag w' m) where
41+ writer _ = W.writer @tag
42+ tell _ = W.tell @tag
43+ listen _ = W.listen @tag
44+ pass _ = W.pass @tag
45+
46+instance {-# OVERLAPPABLE #-}
47+ ( Lift.LiftListen t
48+ , Lift.LiftPass t
49+ , Monad (t m)
50+ , MonadWriter tag w m
51+ , Monoid w
52+ ) => MonadWriter tag w (t m) where
53+ writer t = Lift.lift . writer t
54+ tell t = Lift.lift . tell t
55+ listen t = Lift.liftListen (listen t)
56+ pass t = Lift.liftPass (pass t)
ether/src/Control/Monad/Trans/Ether/Dispatch.hsnew file+270
@@ -0,0 +1,270 @@
1+{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
2+
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE UndecidableInstances #-}
7+{-# LANGUAGE DataKinds #-}
8+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+
10+{- |
11+
12+Type-level machinery to manipulate constraints on the monad
13+transformer stack.
14+
15+Out of the box it provides the following dispatch strategies:
16+
17+* 'tagAttach' to use functions defined using untagged monad classes
18+ as if they were defined using tagged ones.
19+
20+* 'tagReplace' to use functions defined using one tag
21+ as if they were defined using another one.
22+
23+> import qualified Control.Monad.State as T
24+> import Control.Ether.TH (ethereal)
25+> import Control.Monad.Ether.State (MonadState)
26+> import Control.Monad.Trans.Ether.Dispatch (tagAttach, tagDispatch)
27+>
28+> ethereal "Foo" "foo"
29+> ethereal "Bar" "bar"
30+>
31+> f :: T.MonadState Int m => m String
32+> f = fmap show T.get
33+>
34+> g :: MonadState Foo Int m => m String
35+> g = tagAttach foo f
36+>
37+> h :: MonadState Bar Int m => m String
38+> h = tagReplace foo bar g
39+
40+-}
41+
42+module Control.Monad.Trans.Ether.Dispatch
43+ (
44+ -- * The DispatchT monad transformer
45+ DispatchT
46+ , dispatchT
47+ , runDispatchT
48+ , redispatch
49+ -- * Dispatch types and functions
50+ , K_TagAttach(..)
51+ , tagAttach
52+ , K_TagReplace(..)
53+ , tagReplace
54+ ) where
55+
56+import Control.Applicative
57+import Control.Monad (MonadPlus)
58+import Control.Monad.Fix (MonadFix)
59+import Control.Monad.Trans.Class (MonadTrans, lift)
60+import Control.Monad.IO.Class (MonadIO)
61+import Control.Monad.Morph (MFunctor, MMonad)
62+import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
63+
64+import qualified Control.Monad.Base as MB
65+import qualified Control.Monad.Trans.Control as MC
66+import qualified Control.Monad.Trans.Identity as Trans
67+
68+import qualified Control.Monad.Trans.Lift.StT as Lift
69+import qualified Control.Monad.Trans.Lift.Local as Lift
70+import qualified Control.Monad.Trans.Lift.Catch as Lift
71+import qualified Control.Monad.Trans.Lift.Listen as Lift
72+import qualified Control.Monad.Trans.Lift.Pass as Lift
73+import qualified Control.Monad.Trans.Lift.CallCC as Lift
74+
75+import Control.Monad.Ether.Reader.Class
76+import Control.Monad.Ether.State.Class
77+import Control.Monad.Ether.Except.Class
78+import Control.Monad.Ether.Writer.Class
79+
80+import Control.Monad.Ether.Reader as A
81+import Control.Monad.Ether.State.Common as A
82+import Control.Monad.Ether.Except as A
83+import Control.Monad.Ether.Writer as A
84+
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
90+
91+import GHC.Generics (Generic)
92+import Data.Coerce (coerce)
93+
94+-- | Wrap a monad to change its tags. Under the hood this is
95+-- simply 'Trans.IdentityT', all the work is happening on the type level.
96+newtype DispatchT dp m a = DispatchT (Trans.IdentityT m a)
97+ deriving
98+ ( Generic
99+ , Functor, Applicative, Alternative, Monad, MonadPlus
100+ , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
101+ , MonadThrow, MonadCatch, MonadMask )
102+
103+-- | Type-restricted 'coerce'.
104+pack :: forall dp m a . Trans.IdentityT m a -> DispatchT dp m a
105+pack = coerce
106+{-# INLINE pack #-}
107+
108+-- | Type-restricted 'coerce'.
109+unpack :: forall dp m a . DispatchT dp m a -> Trans.IdentityT m a
110+unpack = coerce
111+{-# INLINE unpack #-}
112+
113+-- | Type-restricted 'coerce'.
114+dispatchT :: forall dp m a . m a -> DispatchT dp m a
115+dispatchT = coerce
116+{-# INLINE dispatchT #-}
117+
118+-- | Type-restricted 'coerce'.
119+runDispatchT :: forall dp m a . DispatchT dp m a -> m a
120+runDispatchT = coerce
121+{-# INLINE runDispatchT #-}
122+
123+-- | Type-restricted 'coerce'.
124+redispatch :: forall dp dp' m a . DispatchT dp m a -> DispatchT dp' m a
125+redispatch = coerce
126+{-# INLINE redispatch #-}
127+
128+instance MB.MonadBase b m => MB.MonadBase b (DispatchT dp m) where
129+ liftBase = MB.liftBaseDefault
130+
131+instance MC.MonadTransControl (DispatchT dp) where
132+ type StT (DispatchT dp) a = MC.StT Trans.IdentityT a
133+ liftWith = MC.defaultLiftWith pack unpack
134+ restoreT = MC.defaultRestoreT pack
135+
136+instance MC.MonadBaseControl b m => MC.MonadBaseControl b (DispatchT dp m) where
137+ type StM (DispatchT dp m) a = MC.ComposeSt (DispatchT dp) m a
138+ liftBaseWith = MC.defaultLiftBaseWith
139+ restoreM = MC.defaultRestoreM
140+
141+type instance Lift.StT (DispatchT dp) a = MC.StT (DispatchT dp) a
142+
143+instance Lift.LiftLocal (DispatchT dp) where
144+ liftLocal = Lift.defaultLiftLocal pack unpack
145+
146+instance Lift.LiftCatch (DispatchT dp) where
147+ liftCatch = Lift.defaultLiftCatch pack unpack
148+
149+instance Lift.LiftListen (DispatchT dp) where
150+ liftListen = Lift.defaultLiftListen pack unpack
151+
152+instance Lift.LiftPass (DispatchT dp) where
153+ liftPass = Lift.defaultLiftPass pack unpack
154+
155+instance Lift.LiftCallCC (DispatchT dp) where
156+ liftCallCC = Lift.defaultLiftCallCC pack unpack
157+ liftCallCC' = Lift.defaultLiftCallCC' pack unpack
158+
159+-- Instances for mtl classes
160+
161+instance {-# OVERLAPPABLE #-}
162+ ( Class.MonadCont m
163+ , Monad m
164+ ) => Class.MonadCont (DispatchT dp m)
165+ where
166+ callCC = Lift.liftCallCC' Class.callCC
167+
168+instance {-# OVERLAPPABLE #-}
169+ ( Class.MonadReader r m
170+ , Monad m
171+ ) => Class.MonadReader r (DispatchT dp m)
172+ where
173+ ask = lift Class.ask
174+ local = Lift.liftLocal Class.ask Class.local
175+ reader = lift . Class.reader
176+
177+instance {-# OVERLAPPABLE #-}
178+ ( Class.MonadState s m
179+ , Monad m
180+ ) => Class.MonadState s (DispatchT dp m)
181+ where
182+ get = lift Class.get
183+ put = lift . Class.put
184+ state = lift . Class.state
185+
186+instance {-# OVERLAPPABLE #-}
187+ ( Class.MonadWriter w m
188+ , Monad m
189+ ) => Class.MonadWriter w (DispatchT dp m)
190+ where
191+ writer = lift . Class.writer
192+ tell = lift . Class.tell
193+ listen = Lift.liftListen Class.listen
194+ pass = Lift.liftPass Class.pass
195+
196+instance {-# OVERLAPPABLE #-}
197+ ( Class.MonadError e m
198+ , Monad m
199+ ) => Class.MonadError e (DispatchT dp m)
200+ where
201+ throwError = lift . Class.throwError
202+ catchError = Lift.liftCatch Class.catchError
203+
204+
205+-- TagAttach
206+
207+-- | Encode type-level information for 'tagAttach'.
208+data K_TagAttach t = TagAttach t
209+
210+type DispatchTagAttachT t = DispatchT (TagAttach t)
211+
212+-- | Attach a tag to untagged transformers.
213+tagAttach :: forall tag m a . DispatchTagAttachT tag m a -> m a
214+tagAttach = runDispatchT
215+
216+instance MonadReader tag r m
217+ => Class.MonadReader r (DispatchTagAttachT tag m) where
218+ ask = Lift.lift (A.ask @tag)
219+ local = Lift.liftLocal (A.ask @tag) (A.local @tag)
220+
221+instance MonadState tag s m
222+ => Class.MonadState s (DispatchTagAttachT tag m) where
223+ get = Lift.lift (A.get @tag)
224+ put = Lift.lift . A.put @tag
225+
226+instance MonadExcept tag e m
227+ => Class.MonadError e (DispatchTagAttachT tag m) where
228+ throwError = Lift.lift . A.throw @tag
229+ catchError = Lift.liftCatch (A.catch @tag)
230+
231+instance MonadWriter tag w m
232+ => Class.MonadWriter w (DispatchTagAttachT tag m) where
233+ writer = Lift.lift . A.writer @tag
234+ tell = Lift.lift . A.tell @tag
235+ listen = Lift.liftListen (A.listen @tag)
236+ pass = Lift.liftPass (A.pass @tag)
237+
238+
239+-- TagReplace
240+
241+-- | Encode type-level information for 'tagReplace'.
242+data K_TagReplace tOld tNew = TagReplace tOld tNew
243+
244+type DispatchTagReplaceT tOld tNew = DispatchT (TagReplace tOld tNew)
245+
246+-- | Replace a tag with another tag.
247+tagReplace :: forall tOld tNew m a . DispatchTagReplaceT tOld tNew m a -> m a
248+tagReplace = runDispatchT
249+
250+instance MonadReader tNew r m
251+ => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
252+ ask _ = Lift.lift (A.ask @tNew)
253+ local _ = Lift.liftLocal (A.ask @tNew) (A.local @tNew)
254+
255+instance MonadState tNew s m
256+ => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
257+ get _ = Lift.lift (A.get @tNew)
258+ put _ = Lift.lift . A.put @tNew
259+
260+instance MonadExcept tNew e m
261+ => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
262+ throw _ = Lift.lift . A.throw @tNew
263+ catch _ = Lift.liftCatch (A.catch @tNew)
264+
265+instance MonadWriter tNew w m
266+ => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
267+ writer _ = Lift.lift . A.writer @tNew
268+ tell _ = Lift.lift . A.tell @tNew
269+ listen _ = Lift.liftListen (A.listen @tNew)
270+ pass _ = Lift.liftPass (A.pass @tNew)
ether/src/Control/Monad/Trans/Ether/Except.hsnew file+70
@@ -0,0 +1,70 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
8+
9+-- | See "Control.Monad.Trans.Except".
10+
11+module Control.Monad.Trans.Ether.Except
12+ (
13+ -- * The Except monad
14+ Except
15+ , except
16+ , runExcept
17+ -- * The ExceptT monad transformer
18+ , ExceptT
19+ , exceptT
20+ , runExceptT
21+ -- * Exception operations
22+ , throw
23+ , catch
24+ ) where
25+
26+import Data.Functor.Identity (Identity(..))
27+import qualified Control.Monad.Trans.Except as Trans
28+import Control.Monad.Trans.Ether.Tagged
29+
30+
31+-- | The parameterizable exception monad.
32+--
33+-- Computations are either exceptions or normal values.
34+--
35+-- The 'return' function returns a normal value, while '>>=' exits on
36+-- the first exception.
37+type Except tag e = ExceptT tag e Identity
38+
39+-- | Runs an 'Except' and returns either an exception or a normal value.
40+runExcept :: forall tag e a . Except tag e a -> Either e a
41+runExcept = Trans.runExcept . unpack
42+
43+-- | The exception monad transformer.
44+--
45+-- The 'return' function returns a normal value, while '>>=' exits on
46+-- the first exception.
47+type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
48+
49+-- | Constructor for computations in the exception monad transformer.
50+exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
51+exceptT = pack . Trans.ExceptT
52+
53+-- | Constructor for computations in the exception monad
54+-- (the inverse of 'runExcept').
55+except :: forall tag e m a . Monad m => Either e a -> ExceptT tag e m a
56+except = exceptT @tag . return
57+
58+-- | Runs an 'ExceptT' and returns either an exception or a normal value.
59+runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
60+runExceptT = Trans.runExceptT . unpack
61+
62+-- | Is used within a monadic computation to begin exception processing.
63+throw :: forall tag e m a . Monad m => e -> ExceptT tag e m a
64+throw = pack . Trans.throwE
65+
66+-- | A handler function to handle previous exceptions and return to normal execution.
67+catch
68+ :: forall tag e m a . Monad m
69+ => ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
70+catch m h = pack $ Trans.catchE (unpack m) (unpack . h)
ether/src/Control/Monad/Trans/Ether/Reader.hsnew file+79
@@ -0,0 +1,79 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
8+
9+-- | See "Control.Monad.Trans.Reader".
10+
11+module Control.Monad.Trans.Ether.Reader
12+ (
13+ -- * The Reader monad
14+ Reader
15+ , reader
16+ , runReader
17+ -- * The ReaderT monad transformer
18+ , ReaderT
19+ , readerT
20+ , runReaderT
21+ -- * Reader operations
22+ , ask
23+ , local
24+ ) where
25+
26+import Data.Functor.Identity (Identity(..))
27+import qualified Control.Monad.Trans.Reader as Trans
28+import Control.Monad.Trans.Ether.Tagged
29+
30+-- | The parameterizable reader monad.
31+--
32+-- Computations are functions of a shared environment.
33+--
34+-- The 'return' function ignores the environment, while '>>=' passes
35+-- the inherited environment to both subcomputations.
36+type Reader tag r = ReaderT tag r Identity
37+
38+-- | The reader monad transformer,
39+-- which adds a read-only environment to the given monad.
40+--
41+-- The 'return' function ignores the environment, while '>>=' passes
42+-- the inherited environment to both subcomputations.
43+type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
44+
45+-- | Constructor for computations in the reader monad transformer.
46+readerT :: forall tag r m a . (r -> m a) -> ReaderT tag r m a
47+readerT = pack . Trans.ReaderT
48+
49+-- | Constructor for computations in the reader monad
50+-- (the inverse of 'runReader').
51+reader :: forall tag r m a . Monad m => (r -> a) -> ReaderT tag r m a
52+reader = pack . Trans.reader
53+
54+-- | Runs a 'ReaderT' with the given environment
55+-- and returns the final value.
56+runReaderT :: forall tag r m a . ReaderT tag r m a -> r -> m a
57+runReaderT = Trans.runReaderT . unpack
58+
59+-- | Runs a 'ReaderT' with the given environment
60+-- and returns the final value.
61+runReader :: forall tag r a . Reader tag r a -> r -> a
62+runReader = Trans.runReader . unpack
63+
64+-- | Fetch the value of the environment.
65+ask :: forall tag r m . Monad m => ReaderT tag r m r
66+ask = pack Trans.ask
67+
68+-- | Execute a computation in a modified environment
69+-- (a specialization of 'withReaderT').
70+--
71+-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
72+local
73+ :: forall tag r m a
74+ . (r -> r)
75+ -- ^ The function to modify the environment.
76+ -> ReaderT tag r m a
77+ -- ^ Computation to run in the modified environment.
78+ -> ReaderT tag r m a
79+local f = pack . Trans.withReaderT f . unpack
ether/src/Control/Monad/Trans/Ether/State.hsnew file+8
@@ -0,0 +1,8 @@
1+
2+-- | See "Control.Monad.Trans.State".
3+
4+module Control.Monad.Trans.Ether.State
5+ ( module Control.Monad.Trans.Ether.State.Lazy
6+ ) where
7+
8+import Control.Monad.Trans.Ether.State.Lazy
ether/src/Control/Monad/Trans/Ether/State/Lazy.hsnew file+93
@@ -0,0 +1,93 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
8+
9+-- | See "Control.Monad.Trans.State.Lazy".
10+
11+module Control.Monad.Trans.Ether.State.Lazy
12+ (
13+ -- * The State monad
14+ State
15+ , state
16+ , runState
17+ , evalState
18+ , execState
19+ -- * The StateT monad transformer
20+ , StateT
21+ , stateT
22+ , runStateT
23+ , evalStateT
24+ , execStateT
25+ -- * State operations
26+ , get
27+ , put
28+ ) where
29+
30+import Data.Functor.Identity (Identity(..))
31+import qualified Control.Monad.Trans.State.Lazy as Trans
32+import Control.Monad.Trans.Ether.Tagged
33+
34+-- | The parametrizable state monad.
35+--
36+-- Computations have access to a mutable state.
37+--
38+-- The 'return' function leaves the state unchanged, while '>>=' uses
39+-- the final state of the first computation as the initial state of the second.
40+type State tag r = StateT tag r Identity
41+
42+-- | The state monad transformer.
43+--
44+-- The 'return' function leaves the state unchanged, while '>>=' uses
45+-- the final state of the first computation as the initial state of the second.
46+type StateT tag s = TaggedTrans tag (Trans.StateT s)
47+
48+-- | Constructor for computations in the state monad transformer.
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
50+stateT = pack . Trans.StateT
51+
52+-- | Constructor for computations in the state monad
53+-- (the inverse of 'runState').
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
55+state = pack . Trans.state
56+
57+-- | Runs a 'StateT' with the given initial state
58+-- and returns both the final value and the final state.
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
60+runStateT = Trans.runStateT . unpack
61+
62+-- | Runs a 'StateT' with the given initial state
63+-- and returns the final value, discarding the final state.
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
65+evalStateT = Trans.evalStateT . unpack
66+
67+-- | Runs a 'StateT' with the given initial state
68+-- and returns the final state, discarding the final value.
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
70+execStateT = Trans.execStateT . unpack
71+
72+-- | Runs a 'State' with the given initial state
73+-- and returns both the final value and the final state.
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
75+runState = Trans.runState . unpack
76+
77+-- | Runs a 'State' with the given initial state
78+-- and returns the final value, discarding the final state.
79+evalState :: forall tag s a . State tag s a -> s -> a
80+evalState = Trans.evalState . unpack
81+
82+-- | Runs a 'State' with the given initial state
83+-- and returns the final state, discarding the final value.
84+execState :: forall tag s a . State tag s a -> s -> s
85+execState = Trans.execState . unpack
86+
87+-- | Fetch the current value of the state within the monad.
88+get :: forall tag s m . Monad m => StateT tag s m s
89+get = pack Trans.get
90+
91+-- | Set the value of the state within the monad.
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
93+put = pack . Trans.put
ether/src/Control/Monad/Trans/Ether/State/Strict.hsnew file+93
@@ -0,0 +1,93 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
8+
9+-- | See "Control.Monad.Trans.State.Strict".
10+
11+module Control.Monad.Trans.Ether.State.Strict
12+ (
13+ -- * The State monad
14+ State
15+ , state
16+ , runState
17+ , evalState
18+ , execState
19+ -- * The StateT monad transformer
20+ , StateT
21+ , stateT
22+ , runStateT
23+ , evalStateT
24+ , execStateT
25+ -- * State operations
26+ , get
27+ , put
28+ ) where
29+
30+import Data.Functor.Identity (Identity(..))
31+import qualified Control.Monad.Trans.State.Strict as Trans
32+import Control.Monad.Trans.Ether.Tagged
33+
34+-- | The parametrizable state monad.
35+--
36+-- Computations have access to a mutable state.
37+--
38+-- The 'return' function leaves the state unchanged, while '>>=' uses
39+-- the final state of the first computation as the initial state of the second.
40+type State tag r = StateT tag r Identity
41+
42+-- | The state monad transformer.
43+--
44+-- The 'return' function leaves the state unchanged, while '>>=' uses
45+-- the final state of the first computation as the initial state of the second.
46+type StateT tag s = TaggedTrans tag (Trans.StateT s)
47+
48+-- | Constructor for computations in the state monad transformer.
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
50+stateT = pack . Trans.StateT
51+
52+-- | Constructor for computations in the state monad
53+-- (the inverse of 'runState').
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
55+state = pack . Trans.state
56+
57+-- | Runs a 'StateT' with the given initial state
58+-- and returns both the final value and the final state.
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
60+runStateT = Trans.runStateT . unpack
61+
62+-- | Runs a 'StateT' with the given initial state
63+-- and returns the final value, discarding the final state.
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
65+evalStateT = Trans.evalStateT . unpack
66+
67+-- | Runs a 'StateT' with the given initial state
68+-- and returns the final state, discarding the final value.
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
70+execStateT = Trans.execStateT . unpack
71+
72+-- | Runs a 'State' with the given initial state
73+-- and returns both the final value and the final state.
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
75+runState = Trans.runState . unpack
76+
77+-- | Runs a 'State' with the given initial state
78+-- and returns the final value, discarding the final state.
79+evalState :: forall tag s a . State tag s a -> s -> a
80+evalState = Trans.evalState . unpack
81+
82+-- | Runs a 'State' with the given initial state
83+-- and returns the final state, discarding the final value.
84+execState :: forall tag s a . State tag s a -> s -> s
85+execState = Trans.execState . unpack
86+
87+-- | Fetch the current value of the state within the monad.
88+get :: forall tag s m . Monad m => StateT tag s m s
89+get = pack Trans.get
90+
91+-- | Set the value of the state within the monad.
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
93+put = pack . Trans.put
ether/src/Control/Monad/Trans/Ether/Tagged.hsnew file+150
@@ -0,0 +1,150 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE ConstraintKinds #-}
6+{-# LANGUAGE TypeFamilies #-}
7+
8+-- | This module defines the core data type of Ether, 'TaggedTrans',
9+-- and a bunch of instances for it. 'TaggedTrans' attaches a tag to
10+-- an existing monad transformer.
11+
12+module Control.Monad.Trans.Ether.Tagged where
13+
14+import Control.Applicative
15+import Control.Monad (MonadPlus)
16+import Control.Monad.Fix (MonadFix)
17+import Control.Monad.Trans.Class (MonadTrans, lift)
18+import Control.Monad.IO.Class (MonadIO)
19+import Control.Monad.Morph (MFunctor, MMonad)
20+import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
21+
22+import qualified Control.Monad.Base as MB
23+import qualified Control.Monad.Trans.Control as MC
24+
25+import qualified Control.Monad.Trans.Lift.StT as Lift
26+import qualified Control.Monad.Trans.Lift.Local as Lift
27+import qualified Control.Monad.Trans.Lift.Catch as Lift
28+import qualified Control.Monad.Trans.Lift.Listen as Lift
29+import qualified Control.Monad.Trans.Lift.Pass as Lift
30+import qualified Control.Monad.Trans.Lift.CallCC as Lift
31+
32+import qualified Control.Monad.Cont.Class as Class
33+import qualified Control.Monad.Reader.Class as Class
34+import qualified Control.Monad.State.Class as Class
35+import qualified Control.Monad.Writer.Class as Class
36+import qualified Control.Monad.Error.Class as Class
37+
38+import GHC.Generics (Generic)
39+import Data.Coerce (coerce)
40+
41+-- | Tagged monad transformer.
42+newtype TaggedTrans tag trans (m :: * -> *) a = TaggedTrans (trans m a)
43+ deriving
44+ ( Generic
45+ , Functor, Applicative, Alternative, Monad, MonadPlus
46+ , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad
47+ , MonadThrow, MonadCatch, MonadMask )
48+
49+-- | Type-restricted 'coerce'.
50+pack :: trans m a -> TaggedTrans tag trans m a
51+pack = coerce
52+
53+-- | Type-restricted 'coerce'.
54+unpack :: TaggedTrans tag trans m a -> trans m a
55+unpack = coerce
56+
57+instance
58+ ( MB.MonadBase b m
59+ , MonadTrans trans
60+ , Monad (trans m)
61+ ) => MB.MonadBase b (TaggedTrans tag trans m)
62+ where
63+ liftBase = MB.liftBaseDefault
64+
65+instance
66+ ( MC.MonadTransControl trans
67+ ) => MC.MonadTransControl (TaggedTrans tag trans)
68+ where
69+ type StT (TaggedTrans tag trans) a = MC.StT trans a
70+ liftWith = MC.defaultLiftWith pack unpack
71+ restoreT = MC.defaultRestoreT pack
72+
73+instance
74+ ( MC.MonadBaseControl b m
75+ , MC.MonadTransControl trans
76+ , Monad (trans m)
77+ ) => MC.MonadBaseControl b (TaggedTrans tag trans m)
78+ where
79+ type StM (TaggedTrans tag trans m) a = MC.ComposeSt trans m a
80+ liftBaseWith = MC.defaultLiftBaseWith
81+ restoreM = MC.defaultRestoreM
82+
83+type instance Lift.StT (TaggedTrans tag trans) a = Lift.StT trans a
84+
85+instance Lift.LiftLocal trans => Lift.LiftLocal (TaggedTrans tag trans) where
86+ liftLocal = Lift.defaultLiftLocal pack unpack
87+
88+instance Lift.LiftCatch trans => Lift.LiftCatch (TaggedTrans tag trans) where
89+ liftCatch = Lift.defaultLiftCatch pack unpack
90+
91+instance Lift.LiftListen trans => Lift.LiftListen (TaggedTrans tag trans) where
92+ liftListen = Lift.defaultLiftListen pack unpack
93+
94+instance Lift.LiftPass trans => Lift.LiftPass (TaggedTrans tag trans) where
95+ liftPass = Lift.defaultLiftPass pack unpack
96+
97+instance Lift.LiftCallCC trans => Lift.LiftCallCC (TaggedTrans tag trans) where
98+ liftCallCC = Lift.defaultLiftCallCC pack unpack
99+ liftCallCC' = Lift.defaultLiftCallCC' pack unpack
100+
101+-- Instances for mtl classes
102+
103+instance
104+ ( Class.MonadCont m
105+ , Lift.LiftCallCC trans
106+ , Monad (trans m)
107+ ) => Class.MonadCont (TaggedTrans tag trans m)
108+ where
109+ callCC = Lift.liftCallCC' Class.callCC
110+
111+instance
112+ ( Class.MonadReader r m
113+ , Lift.LiftLocal trans
114+ , Monad (trans m)
115+ ) => Class.MonadReader r (TaggedTrans tag trans m)
116+ where
117+ ask = lift Class.ask
118+ local = Lift.liftLocal Class.ask Class.local
119+ reader = lift . Class.reader
120+
121+instance
122+ ( Class.MonadState s m
123+ , MonadTrans trans
124+ , Monad (trans m)
125+ ) => Class.MonadState s (TaggedTrans tag trans m)
126+ where
127+ get = lift Class.get
128+ put = lift . Class.put
129+ state = lift . Class.state
130+
131+instance
132+ ( Class.MonadWriter w m
133+ , Lift.LiftListen trans
134+ , Lift.LiftPass trans
135+ , Monad (trans m)
136+ ) => Class.MonadWriter w (TaggedTrans tag trans m)
137+ where
138+ writer = lift . Class.writer
139+ tell = lift . Class.tell
140+ listen = Lift.liftListen Class.listen
141+ pass = Lift.liftPass Class.pass
142+
143+instance
144+ ( Class.MonadError e m
145+ , Lift.LiftCatch trans
146+ , Monad (trans m)
147+ ) => Class.MonadError e (TaggedTrans tag trans m)
148+ where
149+ throwError = lift . Class.throwError
150+ catchError = Lift.liftCatch Class.catchError
ether/src/Control/Monad/Trans/Ether/Writer.hsnew file+87
@@ -0,0 +1,87 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE DataKinds #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
8+
9+-- | See "Control.Monad.Trans.Writer".
10+
11+module Control.Monad.Trans.Ether.Writer
12+ (
13+ -- * The Writer monad
14+ Writer
15+ , writer
16+ , runWriter
17+ , execWriter
18+ -- * The WriterT monad transformer
19+ , WriterT
20+ , writerT
21+ , runWriterT
22+ , execWriterT
23+ -- * Writer operations
24+ , tell
25+ , listen
26+ , pass
27+ ) where
28+
29+import Data.Functor.Identity (Identity(..))
30+import qualified Control.Monad.Trans.Writer.Lazy as Trans
31+import Control.Monad.Trans.Ether.Tagged
32+
33+-- | The parametrizable writer monad.
34+--
35+-- Computations can accumulate a monoid value.
36+--
37+-- The 'return' function produces the output 'mempty', while '>>=' combines
38+-- the outputs of the subcomputations using 'mappend'.
39+type Writer tag w = WriterT tag w Identity
40+
41+-- | The writer monad transformer.
42+--
43+-- The 'return' function produces the output 'mempty', while '>>=' combines
44+-- the outputs of the subcomputations using 'mappend'.
45+type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
46+
47+-- | Constructor for computations in the writer monad transformer.
48+writerT :: forall tag w m a . m (a, w) -> WriterT tag w m a
49+writerT = pack . Trans.WriterT
50+
51+-- | Constructor for computations in the writer monad
52+-- (the inverse of 'runWriter').
53+writer :: forall tag w m a . Monad m => (a, w) -> WriterT tag w m a
54+writer = pack . Trans.writer
55+
56+-- | Runs a 'WriterT' and returns both the normal value
57+-- and the final accumulator.
58+runWriterT :: forall tag w m a . WriterT tag w m a -> m (a, w)
59+runWriterT = Trans.runWriterT . unpack
60+
61+-- | Runs a 'Writer' and returns both the normal value
62+-- and the final accumulator.
63+runWriter :: forall tag w a . Writer tag w a -> (a, w)
64+runWriter = Trans.runWriter . unpack
65+
66+-- | Runs a 'WriterT' and returns the final accumulator,
67+-- discarding the normal value.
68+execWriterT :: forall tag w m a . Monad m => WriterT tag w m a -> m w
69+execWriterT = Trans.execWriterT . unpack
70+
71+-- | Runs a 'Writer' and returns the final accumulator,
72+-- discarding the normal value.
73+execWriter :: forall tag w a . Writer tag w a -> w
74+execWriter = Trans.execWriter . unpack
75+
76+-- | Appends a value to the accumulator within the monad.
77+tell :: forall tag w m . Monad m => w -> WriterT tag w m ()
78+tell w = writer @tag ((), w)
79+
80+-- | Executes an action and adds its accumulator to the value of the computation.
81+listen :: forall tag w m a . Monad m => WriterT tag w m a -> WriterT tag w m (a, w)
82+listen = pack . Trans.listen . unpack
83+
84+-- | Executes an action which returns a value and a function, and returns the
85+-- value, applying the function to the accumulator.
86+pass :: forall tag w m a . Monad m => WriterT tag w m (a, w -> w) -> WriterT tag w m a
87+pass = pack . Trans.pass . unpack
shell.nixdeleted−22
@@ -1,22 +0,0 @@
1−{ pkgs ? import <nixpkgs> {},
2− hc ? "ghc844"
3−}:
4−
5−pkgs.stdenv.mkDerivation rec {
6− name = "ether";
7− buildInputs = [
8− pkgs.haskell.compiler.${hc}
9− pkgs.git
10− pkgs.zlib
11− pkgs.cabal-install
12− pkgs.pkgconfig
13− ];
14− shellHook = ''
15− export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath buildInputs}:$LD_LIBRARY_PATH
16− export LANG=en_US.UTF-8
17− '';
18− LOCALE_ARCHIVE =
19− if pkgs.stdenv.isLinux
20− then "${pkgs.glibcLocales}/lib/locale/locale-archive"
21− else "";
22−}
src/Ether.hsdeleted−25
@@ -1,25 +0,0 @@
1−module Ether
2− ( module Control.Monad
3− , module Control.Monad.Fix
4− , module Control.Monad.Trans.Identity
5− , module Data.Functor.Identity
6− , module Data.Tagged
7− , module Ether.Reader
8− , module Ether.Writer
9− , module Ether.State
10− , module Ether.Except
11− , module Ether.TagDispatch
12− , module Ether.TaggedTrans
13− ) where
14−
15−import Control.Monad
16−import Control.Monad.Fix
17−import Control.Monad.Trans.Identity
18−import Data.Functor.Identity
19−import Data.Tagged
20−import Ether.Reader
21−import Ether.Writer
22−import Ether.State
23−import Ether.Except
24−import Ether.TagDispatch
25−import Ether.TaggedTrans
src/Ether/Except.hsdeleted−127
@@ -1,127 +0,0 @@
1−module Ether.Except
2− (
3− -- * MonadExcept class
4− MonadExcept
5− , throw
6− , catch
7− -- * The Except monad
8− , Except
9− , runExcept
10− -- * The ExceptT monad transformer
11− , ExceptT
12− , exceptT
13− , runExceptT
14− -- * MonadExcept class (implicit)
15− , MonadExcept'
16− , throw'
17− , catch'
18− -- * The Except monad (implicit)
19− , Except'
20− , runExcept'
21− -- * The ExceptT monad transformer (implicit)
22− , ExceptT'
23− , exceptT'
24− , runExceptT'
25− -- * Internal labels
26− , TAGGED
27− , EXCEPT
28− ) where
29−
30−import qualified Control.Monad.Except as T
31−import Control.Monad.Signatures (Catch)
32−import qualified Control.Monad.Trans.Lift.Catch as Lift
33−import Data.Coerce
34−import Data.Functor.Identity
35−
36−import Ether.TaggedTrans
37−import Ether.Internal
38−
39−class Monad m => MonadExcept tag e m | m tag -> e where
40−
41− -- | Is used within a monadic computation to begin exception processing.
42− throw :: e -> m a
43−
44− -- | A TaggedTrans function to handle previous exceptions and return to
45− -- normal execution.
46− catch :: m a -> (e -> m a) -> m a
47−
48−instance {-# OVERLAPPABLE #-}
49− ( Lift.LiftCatch t
50− , Monad (t m)
51− , MonadExcept tag e m
52− ) => MonadExcept tag e (t m) where
53− throw = Lift.lift . throw @tag
54− catch = Lift.liftCatch (catch @tag)
55−
56−-- | Encode type-level information for 'ExceptT'.
57−data EXCEPT
58−
59−-- | The parameterizable exception monad.
60−--
61−-- Computations are either exceptions or normal values.
62−--
63−-- The 'return' function returns a normal value, while '>>=' exits on
64−-- the first exception.
65−type Except tag e = ExceptT tag e Identity
66−
67−-- | The exception monad transformer.
68−--
69−-- The 'return' function returns a normal value, while '>>=' exits on
70−-- the first exception.
71−type ExceptT tag e = TaggedTrans (TAGGED EXCEPT tag) (T.ExceptT e)
72−
73−-- | Runs an 'Except' and returns either an exception or a normal value.
74−runExcept :: forall tag e a . Except tag e a -> Either e a
75−runExcept = coerce (T.runExcept @e @a)
76−
77−-- | Runs an 'ExceptT' and returns either an exception or a normal value.
78−runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
79−runExceptT = coerce (T.runExceptT @e @m @a)
80−
81−-- | Constructor for computations in the exception monad transformer.
82−exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
83−exceptT = coerce (T.ExceptT @e @m @a)
84−
85−type instance HandleSuper EXCEPT e trans = ()
86−type instance HandleConstraint EXCEPT e trans m =
87− T.MonadError e (trans m)
88−
89−instance Handle EXCEPT e (T.ExceptT e) where
90− handling r = r
91−
92−instance
93− ( Handle EXCEPT e trans
94− , Monad m, Monad (trans m)
95− ) => MonadExcept tag e (TaggedTrans (TAGGED EXCEPT tag) trans m)
96− where
97−
98− throw =
99− handling @EXCEPT @e @trans @m $
100− coerce (T.throwError @e @(trans m) @a) ::
101− forall eff a . e -> TaggedTrans eff trans m a
102−
103− catch =
104− handling @EXCEPT @e @trans @m $
105− coerce (T.catchError @e @(trans m) @a) ::
106− forall eff a . Catch e (TaggedTrans eff trans m) a
107−
108−type MonadExcept' e = MonadExcept e e
109−
110−throw' :: forall e m a . MonadExcept' e m => e -> m a
111−throw' = throw @e
112−
113−catch' :: forall e m a . MonadExcept' e m => m a -> (e -> m a) -> m a
114−catch' = catch @e
115−
116−type Except' e = Except e e
117−
118−runExcept' :: Except' e a -> Either e a
119−runExcept' = runExcept
120−
121−type ExceptT' e = ExceptT e e
122−
123−exceptT' :: m (Either e a) -> ExceptT' e m a
124−exceptT' = exceptT
125−
126−runExceptT' :: ExceptT' e m a -> m (Either e a)
127−runExceptT' = runExceptT
src/Ether/Internal.hsdeleted−68
@@ -1,68 +0,0 @@
1−module Ether.Internal
2− ( Tagged(..)
3− , TagsK
4− , Tags
5− , HasLens(..)
6− , LensLike
7− , Lens
8− , Lens'
9− , ReifiedLens(..)
10− , ReifiedLens'
11− , view
12− , over
13− , HList(..)
14− , KindOf
15− , TAGGED
16− , HandleSuper
17− , HandleConstraint
18− , Handle(..)
19− , makeTupleInstancesHasLens
20− ) where
21−
22−import Control.Applicative
23−import Data.Coerce
24−import Data.Functor.Identity
25−import Data.Kind
26−import Data.Tagged
27−import GHC.Exts (Constraint)
28−
29−import Ether.Internal.HasLens
30−import Ether.Internal.Tags
31−import Ether.Internal.TH_TupleInstances (makeTupleInstancesHasLens)
32−import Ether.Internal.TupleInstances ()
33−
34−data TAGGED e t
35−
36−type K_Monad = Type -> Type
37−
38−type K_Trans = K_Monad -> K_Monad
39−
40−type family
41− HandleSuper
42− (eff :: keff)
43− (p :: kp)
44− (trans :: K_Trans)
45− :: Constraint
46−
47−type family
48− HandleConstraint
49− (eff :: keff)
50− (p :: kp)
51− (trans :: K_Trans) (m :: K_Monad)
52− :: Constraint
53−
54−class
55− HandleSuper eff p trans =>
56− Handle eff p (trans :: K_Trans) | eff trans -> p
57− where
58− handling :: Monad m => (HandleConstraint eff p trans m => r) -> r
59−
60−newtype ReifiedLens s t a b = Lens (Lens s t a b)
61−
62−type ReifiedLens' s a = ReifiedLens s s a a
63−
64−view :: LensLike (Const a) s t a b -> s -> a
65−view l = coerce (l Const)
66−
67−over :: LensLike Identity s t a b -> (a -> b) -> s -> t
68−over = coerce
src/Ether/Internal/HasLens.hsdeleted−24
@@ -1,24 +0,0 @@
1−module Ether.Internal.HasLens
2− ( LensLike
3− , Lens
4− , Lens'
5− , HasLens(..)
6− ) where
7−
8−import Data.Tagged
9−import Data.Coerce
10−
11−type LensLike f s t a b = (a -> f b) -> s -> f t
12−
13−type Lens s t a b = forall f. Functor f => LensLike f s t a b
14−
15−type Lens' s a = Lens s s a a
16−
17−class HasLens tag outer inner | tag outer -> inner where
18− lensOf :: Lens' outer inner
19−
20−instance HasLens a a a where
21− lensOf = id
22−
23−instance HasLens t (Tagged t a) a where
24− lensOf = \f -> fmap coerce . f . coerce
src/Ether/Internal/TH_TupleInstances.hsdeleted−79
@@ -1,79 +0,0 @@
1−module Ether.Internal.TH_TupleInstances
2− ( makeTupleInstancesTagsK
3− , makeTupleInstancesTags
4− , makeTupleInstancesHasLens
5− ) where
6−
7−import Data.Tagged
8−import Data.Traversable
9−import Data.List as List
10−import qualified Language.Haskell.TH as TH
11−
12−import Ether.Internal.HasLens
13−import Ether.Internal.Tags
14−import Ether.Internal.TH_Utils
15−
16−makeTupleInstancesTagsK :: TH.DecsQ
17−makeTupleInstancesTagsK = do
18− for [2..tupCount] $ \n -> do
19− let
20− tupTy = List.foldl' TH.AppT (TH.ConT (TH.tupleTypeName n)) $
21− (\k -> TH.ConT ''Tagged `TH.AppT`
22− TH.VarT (tagName k) `TH.AppT`
23− TH.VarT (varName k)) <$> [0..n-1]
24− tagsList = List.foldr
25− (\a b -> TH.PromotedConsT `TH.AppT` a `TH.AppT` b)
26− TH.PromotedNilT
27− (TH.AppT (TH.ConT ''KindOf) . TH.VarT . tagName <$> [0..n-1])
28− return $
29− TH.TySynInstD ''TagsK (TH.TySynEqn [tupTy] tagsList)
30−
31−makeTupleInstancesTags :: TH.DecsQ
32−makeTupleInstancesTags = do
33− for [2..tupCount] $ \n -> do
34− let
35− tupTy = List.foldl' TH.AppT (TH.ConT (TH.tupleTypeName n)) $
36− (\k -> TH.ConT ''Tagged `TH.AppT`
37− TH.VarT (tagName k) `TH.AppT`
38− TH.VarT (varName k)) <$> [0..n-1]
39− tagsList = List.foldr
40− (\a b -> TH.PromotedT 'HCons `TH.AppT` a `TH.AppT` b)
41− (TH.PromotedT 'HNil)
42− (TH.VarT . tagName <$> [0..n-1])
43− return $
44− TH.TySynInstD ''Tags (TH.TySynEqn [tupTy] tagsList)
45−
46−makeTupleInstancesHasLens :: [Int] -> TH.DecsQ
47−makeTupleInstancesHasLens range = List.concat <$> do
48− for range $ \n ->
49− for [0..n-1] $ \k -> do
50− let
51− tag = TH.mkName "tag"
52− prev = varName <$> [0..k-1]
53− cur = varName k
54− next = varName <$> [k+1..n-1]
55− tupTy = foldl TH.AppT (TH.ConT (TH.tupleTypeName n))
56− ( map TH.VarT prev ++
57− [TH.ConT ''Tagged `TH.AppT` TH.VarT tag `TH.AppT` TH.VarT cur] ++
58− map TH.VarT next )
59− let
60− cur' = TH.mkName "x"
61− f = TH.mkName "f"
62− return $
63− TH.InstanceD Nothing []
64− (TH.ConT ''HasLens `TH.AppT` TH.VarT tag `TH.AppT` tupTy `TH.AppT` TH.VarT cur)
65− [ TH.FunD 'lensOf
66− [ TH.Clause
67− [TH.VarP f, TH.TupP
68− ( map TH.VarP prev ++
69− [TH.ConP 'Tagged [TH.VarP cur]] ++
70− map TH.VarP next )]
71− (TH.NormalB $
72− TH.VarE 'fmap `TH.AppE`
73− (TH.LamE [TH.VarP cur']
74− (TH.TupE
75− ( map TH.VarE prev ++
76− [TH.ConE 'Tagged `TH.AppE` TH.VarE cur'] ++
77− map TH.VarE next ))) `TH.AppE`
78− (TH.VarE f `TH.AppE` TH.VarE cur) )
79− [] ] ]
src/Ether/Internal/TH_Utils.hsdeleted−14
@@ -1,14 +0,0 @@
1−module Ether.Internal.TH_Utils
2− ( tupCount
3− , varName
4− , tagName
5− ) where
6−
7−import qualified Language.Haskell.TH as TH
8−
9−tupCount :: Int
10−tupCount = 62
11−
12−varName, tagName :: Int -> TH.Name
13−varName k = TH.mkName ('a' : show k)
14−tagName k = TH.mkName ('t' : show k)
src/Ether/Internal/Tags.hsdeleted−18
@@ -1,18 +0,0 @@
1−module Ether.Internal.Tags
2− ( Tags
3− , TagsK
4− , HList(..)
5− , KindOf
6− ) where
7−
8−import Data.Kind
9−
10−data HList xs where
11− HNil :: HList '[]
12− HCons :: x -> HList xs -> HList (x ': xs)
13−
14−type KindOf (a :: k) = k
15−
16−type family TagsK (p :: Type) :: [Type]
17−type family Tags (p :: Type) :: HList (TagsK p)
18−
src/Ether/Internal/TupleInstances.hsdeleted−24
@@ -1,24 +0,0 @@
1−{-# OPTIONS -fno-warn-orphans #-}
2−{-# LANGUAGE CPP #-}
3−
4−module Ether.Internal.TupleInstances () where
5−
6−import Data.Tagged
7−import Ether.Internal.Tags
8−import Ether.Internal.TH_TupleInstances
9−
10−type instance TagsK () = '[]
11−type instance TagsK (Tagged t a) = '[KindOf t]
12−type instance TagsK (Tagged t0 a, Tagged t1 b) = '[KindOf t0, KindOf t1]
13−
14−makeTupleInstancesTagsK
15−
16−type instance Tags () = 'HNil
17−type instance Tags (Tagged t a) = 'HCons t 'HNil
18−type instance Tags (Tagged t0 a, Tagged t1 b) = 'HCons t0 ('HCons t1 'HNil)
19−
20−makeTupleInstancesTags
21−
22−#ifndef DISABLE_TUP_INSTANCES
23−makeTupleInstancesHasLens [2..62]
24−#endif
src/Ether/Reader.hsdeleted−236
@@ -1,236 +0,0 @@
1−module Ether.Reader
2− (
3− -- * MonadReader class
4− MonadReader
5− , ask
6− , local
7− , reader
8− , asks
9− -- * The Reader monad
10− , Reader
11− , runReader
12− -- * The ReaderT monad transformer
13− , ReaderT
14− , readerT
15− , runReaderT
16− -- * The Reader monad (flattened)
17− , Readers
18− , runReaders
19− -- * The ReaderT monad transformer (flattened)
20− , ReadersT
21− , runReadersT
22− -- * MonadReader class (implicit)
23− , MonadReader'
24− , local'
25− , ask'
26− , reader'
27− , asks'
28− -- * The Reader monad (implicit)
29− , Reader'
30− , runReader'
31− -- * The ReaderT monad transformer (implicit)
32− , ReaderT'
33− , readerT'
34− , runReaderT'
35− -- * Internal labels
36− , TAGGED
37− , READER
38− , READERS
39− ) where
40−
41−import qualified Control.Monad.Reader as T
42−import qualified Control.Monad.Trans.Lift.Local as Lift
43−import Control.Monad.Trans.Lift.Local (Local)
44−import Data.Coerce
45−import Data.Functor.Identity
46−import Data.Kind
47−
48−import Ether.TaggedTrans
49−import Ether.Internal
50−
51−class Monad m => MonadReader tag r m | m tag -> r where
52−
53− {-# MINIMAL (ask | reader), local #-}
54−
55− -- | Retrieves the monad environment.
56− ask :: m r
57− ask = reader @tag id
58−
59− -- | Executes a computation in a modified environment.
60− local
61− :: (r -> r)
62− -- ^ The function to modify the environment.
63− -> m a
64− -- ^ @Reader@ to run in the modified environment.
65− -> m a
66−
67− -- | Retrieves a function of the current environment.
68− reader
69− :: (r -> a)
70− -- ^ The selector function to apply to the environment.
71− -> m a
72− reader f = fmap f (ask @tag)
73−
74−instance {-# OVERLAPPABLE #-}
75− ( Lift.LiftLocal t
76− , Monad (t m)
77− , MonadReader tag r m
78− ) => MonadReader tag r (t m)
79− where
80− ask = Lift.lift (ask @tag)
81− local = Lift.liftLocal (ask @tag) (local @tag)
82− reader = Lift.lift . reader @tag
83−
84−instance {-# OVERLAPPABLE #-}
85− ( Monad (trans m)
86− , MonadReader tag r (TaggedTrans effs trans m)
87− ) => MonadReader tag r (TaggedTrans (eff ': effs) trans (m :: Type -> Type))
88− where
89−
90− ask =
91− (coerce ::
92− TaggedTrans effs trans m r ->
93− TaggedTrans (eff ': effs) trans m r)
94− (ask @tag)
95−
96− local =
97− (coerce :: forall a .
98− Lift.Local r (TaggedTrans effs trans m) a ->
99− Lift.Local r (TaggedTrans (eff ': effs) trans m) a)
100− (local @tag)
101−
102− reader =
103− (coerce :: forall a .
104− ((r -> a) -> TaggedTrans effs trans m a) ->
105− ((r -> a) -> TaggedTrans (eff ': effs) trans m a))
106− (reader @tag)
107−
108−-- | Retrieves a function of the current environment.
109−asks
110− :: forall tag r m a
111− . MonadReader tag r m
112− => (r -> a)
113− -- ^ The selector function to apply to the environment.
114− -> m a
115−asks = reader @tag
116−
117−-- | Encode type-level information for 'ReaderT'.
118−data READER
119−
120−-- | The parameterizable reader monad.
121−--
122−-- Computations are functions of a shared environment.
123−--
124−-- The 'return' function ignores the environment, while '>>=' passes
125−-- the inherited environment to both subcomputations.
126−type Reader tag r = ReaderT tag r Identity
127−
128−-- | The reader monad transformer,
129−-- which adds a read-only environment to the given monad.
130−--
131−-- The 'return' function ignores the environment, while '>>=' passes
132−-- the inherited environment to both subcomputations.
133−type ReaderT tag r = TaggedTrans (TAGGED READER tag) (T.ReaderT r)
134−
135−-- | Constructor for computations in the reader monad transformer.
136−readerT :: forall tag r m a . (r -> m a) -> ReaderT tag r m a
137−readerT = coerce (T.ReaderT @r @m @a)
138−
139−-- | Runs a 'ReaderT' with the given environment
140−-- and returns the final value.
141−runReaderT :: forall tag r m a . ReaderT tag r m a -> r -> m a
142−runReaderT = coerce (T.runReaderT @r @m @a)
143−
144−-- | Runs a 'ReaderT' with the given environment
145−-- and returns the final value.
146−runReader :: forall tag r a . Reader tag r a -> r -> a
147−runReader = coerce (T.runReader @r @a)
148−
149−type instance HandleSuper READER r trans = ()
150−type instance HandleConstraint READER r trans m =
151− T.MonadReader r (trans m)
152−
153−instance Handle READER r (T.ReaderT r) where
154− handling r = r
155−
156−instance
157− ( Handle READER r trans
158− , Monad m, Monad (trans m)
159− ) => MonadReader tag r (TaggedTrans (TAGGED READER tag) trans m)
160− where
161−
162− ask =
163− handling @READER @r @trans @m $
164− coerce (T.ask @r @(trans m))
165−
166− local =
167− handling @READER @r @trans @m $
168− coerce (T.local @r @(trans m) @a) ::
169− forall eff a . Local r (TaggedTrans eff trans m) a
170−
171− reader =
172− handling @READER @r @trans @m $
173− coerce (T.reader @r @(trans m) @a) ::
174− forall eff a . (r -> a) -> TaggedTrans eff trans m a
175−
176−instance
177− ( HasLens tag payload r
178− , Handle READER payload trans
179− , Monad m, Monad (trans m)
180− ) => MonadReader tag r (TaggedTrans (TAGGED READER tag ': effs) trans m)
181− where
182−
183− ask =
184− handling @READER @payload @trans @m $
185− (coerce :: forall eff a .
186− trans m a ->
187− TaggedTrans eff trans m a)
188− (T.asks (view (lensOf @tag @payload @r)))
189−
190− local f =
191− handling @READER @payload @trans @m $
192− (coerce :: forall eff a .
193− (trans m a -> trans m a) ->
194− (TaggedTrans eff trans m a -> TaggedTrans eff trans m a))
195− (T.local (over (lensOf @tag @payload @r) f))
196−
197−type family READERS (ts :: HList xs) :: [Type] where
198− READERS 'HNil = '[]
199− READERS ('HCons t ts) = TAGGED READER t ': READERS ts
200−
201−type ReadersT r = TaggedTrans (READERS (Tags r)) (T.ReaderT r)
202−
203−type Readers r = ReadersT r Identity
204−
205−runReadersT :: forall p m a . ReadersT p m a -> p -> m a
206−runReadersT = coerce (T.runReaderT @p @m @a)
207−
208−runReaders :: forall p a . Readers p a -> p -> a
209−runReaders = coerce (T.runReader @p @a)
210−
211−type ReaderT' r = ReaderT r r
212−
213−readerT' :: (r -> m a) -> ReaderT' r m a
214−readerT' = readerT
215−
216−runReaderT' :: ReaderT' r m a -> r -> m a
217−runReaderT' = runReaderT
218−
219−type Reader' r = Reader r r
220−
221−runReader' :: Reader' r a -> r -> a
222−runReader' = runReader
223−
224−type MonadReader' r = MonadReader r r
225−
226−local' :: forall r m a . MonadReader' r m => (r -> r) -> m a -> m a
227−local' = local @r
228−
229−ask' :: forall r m . MonadReader' r m => m r
230−ask' = ask @r
231−
232−reader' :: forall r m a . MonadReader' r m => (r -> a) -> m a
233−reader' = reader @r
234−
235−asks' :: forall r m a . MonadReader' r m => (r -> a) -> m a
236−asks' = asks @r
src/Ether/State.hsdeleted−415
@@ -1,415 +0,0 @@
1−module Ether.State
2− (
3− -- * MonadState class
4− MonadState
5− , get
6− , put
7− , state
8− , modify
9− , gets
10− -- * The State monad
11− , State
12− , runState
13− , evalState
14− , execState
15− -- * The StateT monad transformer
16− , StateT
17− , stateT
18− , runStateT
19− , evalStateT
20− , execStateT
21− -- * The State monad (lazy)
22− , LazyState
23− , runLazyState
24− , evalLazyState
25− , execLazyState
26− -- * The StateT monad transformer (lazy)
27− , LazyStateT
28− , lazyStateT
29− , runLazyStateT
30− , evalLazyStateT
31− , execLazyStateT
32− -- * The State monad (flattened)
33− , States
34− , runStates
35− -- * The StateT monad transformer (flattened)
36− , StatesT
37− , runStatesT
38− -- * MonadState class (implicit)
39− , MonadState'
40− , get'
41− , put'
42− , state'
43− , modify'
44− , gets'
45− -- * The State monad (implicit)
46− , State'
47− , runState'
48− , evalState'
49− , execState'
50− -- * The StateT monad transformer (implicit)
51− , StateT'
52− , stateT'
53− , runStateT'
54− , evalStateT'
55− , execStateT'
56− -- * The State monad (lazy, implicit)
57− , LazyState'
58− , runLazyState'
59− , evalLazyState'
60− , execLazyState'
61− -- * The StateT monad transformer (lazy, implicit)
62− , LazyStateT'
63− , lazyStateT'
64− , runLazyStateT'
65− , evalLazyStateT'
66− , execLazyStateT'
67− -- * Zoom
68− , ZoomT
69− , zoom
70− -- * Internal labels
71− , TAGGED
72− , STATE
73− , STATES
74− , ZOOM
75− ) where
76−
77−import qualified Control.Monad.State.Class as T
78−import qualified Control.Monad.Trans as Lift
79−import Control.Monad.Trans.Identity
80−import qualified Control.Monad.Trans.State.Lazy as T.Lazy
81−import qualified Control.Monad.Trans.State.Strict as T.Strict
82−import Data.Coerce
83−import Data.Functor.Identity
84−import Data.Kind
85−import Data.Proxy
86−import Data.Reflection
87−
88−import Ether.Internal
89−import Ether.TaggedTrans
90−
91−class Monad m => MonadState tag s m | m tag -> s where
92−
93− {-# MINIMAL state | get, put #-}
94−
95− -- | Return the state from the internals of the monad.
96− get :: m s
97− get = state @tag (\s -> (s, s))
98−
99− -- | Replace the state inside the monad.
100− put :: s -> m ()
101− put s = state @tag (\_ -> ((), s))
102−
103− -- | Embed a simple state action into the monad.
104− state :: (s -> (a, s)) -> m a
105− state f = do
106− s <- get @tag
107− let ~(a, s') = f s
108− put @tag s'
109− return a
110−
111−instance {-# OVERLAPPABLE #-}
112− ( Lift.MonadTrans t
113− , Monad (t m)
114− , MonadState tag s m
115− ) => MonadState tag s (t m)
116− where
117− get = Lift.lift (get @tag)
118− put = Lift.lift . put @tag
119− state = Lift.lift . state @tag
120−
121−instance {-# OVERLAPPABLE #-}
122− ( Monad (trans m)
123− , MonadState tag s (TaggedTrans effs trans m)
124− ) => MonadState tag s (TaggedTrans (eff ': effs) trans (m :: Type -> Type))
125− where
126−
127− get =
128− (coerce ::
129− TaggedTrans effs trans m s ->
130− TaggedTrans (eff ': effs) trans m s)
131− (get @tag)
132−
133− put =
134− (coerce ::
135− (s -> TaggedTrans effs trans m ()) ->
136− (s -> TaggedTrans (eff ': effs) trans m ()))
137− (put @tag)
138−
139− state =
140− (coerce :: forall a .
141− ((s -> (a, s)) -> TaggedTrans effs trans m a) ->
142− ((s -> (a, s)) -> TaggedTrans (eff ': effs) trans m a))
143− (state @tag)
144−
145−-- | Modifies the state inside a state monad.
146−modify :: forall tag s m . MonadState tag s m => (s -> s) -> m ()
147−modify f = state @tag (\s -> ((), f s))
148−
149−-- | Gets specific component of the state, using a projection function supplied.
150−gets :: forall tag s m a . MonadState tag s m => (s -> a) -> m a
151−gets f = fmap f (get @tag)
152−
153−-- | Encode type-level information for 'StateT'.
154−data STATE
155−
156−type instance HandleSuper STATE s trans = ()
157−type instance HandleConstraint STATE s trans m =
158− T.MonadState s (trans m)
159−
160−instance Handle STATE s (T.Strict.StateT s) where
161− handling r = r
162−
163−instance Handle STATE s (T.Lazy.StateT s) where
164− handling r = r
165−
166−instance
167− ( Handle STATE s trans
168− , Monad m, Monad (trans m)
169− ) => MonadState tag s (TaggedTrans (TAGGED STATE tag) trans m)
170− where
171−
172− get =
173− handling @STATE @s @trans @m $
174− coerce (T.get @s @(trans m))
175−
176− put =
177− handling @STATE @s @trans @m $
178− coerce (T.put @s @(trans m))
179−
180− state =
181− handling @STATE @s @trans @m $
182− coerce (T.state @s @(trans m) @a) ::
183− forall eff a . (s -> (a, s)) -> TaggedTrans eff trans m a
184−
185−instance
186− ( HasLens tag payload s
187− , Handle STATE payload trans
188− , Monad m, Monad (trans m)
189− ) => MonadState tag s (TaggedTrans (TAGGED STATE tag ': effs) trans m)
190− where
191−
192− get =
193− handling @STATE @payload @trans @m $
194− (coerce :: forall eff a .
195− trans m a ->
196− TaggedTrans eff trans m a)
197− (T.gets (view (lensOf @tag @payload @s)))
198−
199− put s =
200− handling @STATE @payload @trans @m $
201− (coerce :: forall eff a .
202− trans m a ->
203− TaggedTrans eff trans m a)
204− (T.modify (over (lensOf @tag @payload @s) (const s)))
205−
206− state f =
207− handling @STATE @payload @trans @m $
208− (coerce :: forall eff a .
209− trans m a ->
210− TaggedTrans eff trans m a)
211− (T.state (lensOf @tag @payload @s f))
212−
213−-- | The parametrizable state monad.
214−--
215−-- Computations have access to a mutable state.
216−--
217−-- The 'return' function leaves the state unchanged, while '>>=' uses
218−-- the final state of the first computation as the initial state of the second.
219−type State tag r = StateT tag r Identity
220−
221−-- | The state monad transformer.
222−--
223−-- The 'return' function leaves the state unchanged, while '>>=' uses
224−-- the final state of the first computation as the initial state of the second.
225−type StateT tag s = TaggedTrans (TAGGED STATE tag) (T.Strict.StateT s)
226−
227−-- | Constructor for computations in the state monad transformer.
228−stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
229−stateT = coerce (T.Strict.StateT @s @m @a)
230−
231−-- | Runs a 'StateT' with the given initial state
232−-- and returns both the final value and the final state.
233−runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
234−runStateT = coerce (T.Strict.runStateT @s @m @a)
235−
236−-- | Runs a 'StateT' with the given initial state
237−-- and returns the final value, discarding the final state.
238−evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
239−evalStateT = coerce (T.Strict.evalStateT @m @s @a)
240−
241−-- | Runs a 'StateT' with the given initial state
242−-- and returns the final state, discarding the final value.
243−execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
244−execStateT = coerce (T.Strict.execStateT @m @s @a)
245−
246−-- | Runs a 'State' with the given initial state
247−-- and returns both the final value and the final state.
248−runState :: forall tag s a . State tag s a -> s -> (a, s)
249−runState = coerce (T.Strict.runState @s @a)
250−
251−-- | Runs a 'State' with the given initial state
252−-- and returns the final value, discarding the final state.
253−evalState :: forall tag s a . State tag s a -> s -> a
254−evalState = coerce (T.Strict.evalState @s @a)
255−
256−-- | Runs a 'State' with the given initial state
257−-- and returns the final state, discarding the final value.
258−execState :: forall tag s a . State tag s a -> s -> s
259−execState = coerce (T.Strict.execState @s @a)
260−
261−-- | The parametrizable state monad.
262−--
263−-- Computations have access to a mutable state.
264−--
265−-- The 'return' function leaves the state unchanged, while '>>=' uses
266−-- the final state of the first computation as the initial state of the second.
267−type LazyState tag r = LazyStateT tag r Identity
268−
269−-- | The state monad transformer.
270−--
271−-- The 'return' function leaves the state unchanged, while '>>=' uses
272−-- the final state of the first computation as the initial state of the second.
273−type LazyStateT tag s = TaggedTrans (TAGGED STATE tag) (T.Lazy.StateT s)
274−
275−-- | Constructor for computations in the state monad transformer.
276−lazyStateT :: forall tag s m a . (s -> m (a, s)) -> LazyStateT tag s m a
277−lazyStateT = coerce (T.Lazy.StateT @s @m @a)
278−
279−-- | Runs a 'StateT' with the given initial state
280−-- and returns both the final value and the final state.
281−runLazyStateT :: forall tag s m a . LazyStateT tag s m a -> s -> m (a, s)
282−runLazyStateT = coerce (T.Lazy.runStateT @s @m @a)
283−
284−-- | Runs a 'StateT' with the given initial state
285−-- and returns the final value, discarding the final state.
286−evalLazyStateT :: forall tag s m a . Monad m => LazyStateT tag s m a -> s -> m a
287−evalLazyStateT = coerce (T.Lazy.evalStateT @m @s @a)
288−
289−-- | Runs a 'StateT' with the given initial state
290−-- and returns the final state, discarding the final value.
291−execLazyStateT :: forall tag s m a . Monad m => LazyStateT tag s m a -> s -> m s
292−execLazyStateT = coerce (T.Lazy.execStateT @m @s @a)
293−
294−-- | Runs a 'State' with the given initial state
295−-- and returns both the final value and the final state.
296−runLazyState :: forall tag s a . LazyState tag s a -> s -> (a, s)
297−runLazyState = coerce (T.Lazy.runState @s @a)
298−
299−-- | Runs a 'State' with the given initial state
300−-- and returns the final value, discarding the final state.
301−evalLazyState :: forall tag s a . LazyState tag s a -> s -> a
302−evalLazyState = coerce (T.Lazy.evalState @s @a)
303−
304−-- | Runs a 'State' with the given initial state
305−-- and returns the final state, discarding the final value.
306−execLazyState :: forall tag s a . LazyState tag s a -> s -> s
307−execLazyState = coerce (T.Lazy.execState @s @a)
308−
309−type family STATES (ts :: HList xs) :: [Type] where
310− STATES 'HNil = '[]
311− STATES ('HCons t ts) = TAGGED STATE t ': STATES ts
312−
313−type StatesT s = TaggedTrans (STATES (Tags s)) (T.Strict.StateT s)
314−
315−type States s = StatesT s Identity
316−
317−runStatesT :: forall p m a . StatesT p m a -> p -> m (a, p)
318−runStatesT = coerce (T.Strict.runStateT @p @m @a)
319−
320−runStates :: forall p a . States p a -> p -> (a, p)
321−runStates = coerce (T.Strict.runState @p @a)
322−
323−type StateT' s = StateT s s
324−
325−stateT' :: (s -> m (a, s)) -> StateT' s m a
326−stateT' = stateT
327−
328−runStateT' :: StateT' s m a -> s -> m (a, s)
329−runStateT' = runStateT
330−
331−runState' :: State' s a -> s -> (a, s)
332−runState' = runState
333−
334−evalStateT' :: Monad m => StateT' s m a -> s -> m a
335−evalStateT' = evalStateT
336−
337−type State' s = State s s
338−
339−evalState' :: State' s a -> s -> a
340−evalState' = evalState
341−
342−execStateT' :: Monad m => StateT' s m a -> s -> m s
343−execStateT' = execStateT
344−
345−execState' :: State' s a -> s -> s
346−execState' = execState
347−
348−type LazyStateT' s = LazyStateT s s
349−
350−lazyStateT' :: (s -> m (a, s)) -> LazyStateT' s m a
351−lazyStateT' = lazyStateT
352−
353−runLazyStateT' :: LazyStateT' s m a -> s -> m (a, s)
354−runLazyStateT' = runLazyStateT
355−
356−runLazyState' :: LazyState' s a -> s -> (a, s)
357−runLazyState' = runLazyState
358−
359−evalLazyStateT' :: Monad m => LazyStateT' s m a -> s -> m a
360−evalLazyStateT' = evalLazyStateT
361−
362−type LazyState' s = LazyState s s
363−
364−evalLazyState' :: LazyState' s a -> s -> a
365−evalLazyState' = evalLazyState
366−
367−execLazyStateT' :: Monad m => LazyStateT' s m a -> s -> m s
368−execLazyStateT' = execLazyStateT
369−
370−execLazyState' :: LazyState' s a -> s -> s
371−execLazyState' = execLazyState
372−
373−type MonadState' s = MonadState s s
374−
375−get' :: forall s m . MonadState' s m => m s
376−get' = get @s
377−
378−gets' :: forall s m a . MonadState' s m => (s -> a) -> m a
379−gets' = gets @s
380−
381−put' :: forall s m . MonadState' s m => s -> m ()
382−put' = put @s
383−
384−state' :: forall s m a . MonadState' s m => (s -> (a, s)) -> m a
385−state' = state @s
386−
387−modify' :: forall s m . MonadState' s m => (s -> s) -> m ()
388−modify' = modify @s
389−
390−-- | Encode type-level information for 'zoom'.
391−data ZOOM t z
392−
393−type ZoomT t (z :: Type) = TaggedTrans (ZOOM t z) IdentityT
394−
395−-- | Zoom into a part of a state using a lens.
396−zoom
397− :: forall tag sOuter sInner m a
398− . Lens' sOuter sInner
399− -> (forall z . Reifies z (ReifiedLens' sOuter sInner) => ZoomT tag z m a)
400− -> m a
401−zoom l m = reify (Lens l) (\(_ :: Proxy z) -> coerce (m @z))
402−
403−instance
404− ( MonadState tag sOuter m
405− , Reifies z (ReifiedLens' sOuter sInner)
406− , trans ~ IdentityT
407− ) => MonadState tag sInner (TaggedTrans (ZOOM tag z) trans m)
408− where
409− state =
410− (coerce :: forall eff r a .
411− (r -> m a) ->
412− (r -> TaggedTrans eff trans m a))
413− (state @tag . l)
414− where
415− Lens l = reflect (Proxy :: Proxy z)
src/Ether/TagDispatch.hsdeleted−138
@@ -1,138 +0,0 @@
1−{- |
2−
3−Type-level machinery to manipulate constraints on the monad
4−transformer stack.
5−
6−Out of the box it provides the following dispatch strategies:
7−
8−* 'tagAttach' to use functions defined using untagged monad classes
9− as if they were defined using tagged ones.
10−
11−* 'tagReplace' to use functions defined using one tag
12− as if they were defined using another one.
13−
14−> import Ether
15−> import Control.Monad.State as Mtl
16−>
17−> data Foo
18−> data Bar
19−>
20−> f :: Mtl.MonadState Int m => m String
21−> f = fmap show Mtl.get
22−>
23−> g :: Ether.MonadState Foo Int m => m String
24−> g = tagAttach @Foo f
25−>
26−> h :: Ether.MonadState Bar Int m => m String
27−> h = tagReplace @Foo @Bar g
28−
29−-}
30−
31−module Ether.TagDispatch
32− (
33− -- * The Tag Attach monad transformer
34− TagAttachT
35− , tagAttach
36− -- * The Tag Replace monad transformer
37− , TagReplaceT
38− , tagReplace
39− -- * Internal labels
40− , TAG_ATTACH
41− , TAG_REPLACE
42− ) where
43−
44−import qualified Control.Monad.Error.Class as Mtl
45−import qualified Control.Monad.Reader.Class as Mtl
46−import qualified Control.Monad.State.Class as Mtl
47−import qualified Control.Monad.Writer.Class as Mtl
48−
49−import Ether.Except
50−import Ether.Reader
51−import Ether.State
52−import Ether.Writer
53−import Ether.TaggedTrans
54−
55−import Control.Monad.Trans.Identity
56−import Data.Coerce
57−
58−-- | Encode type-level information for 'tagAttach'.
59−data TAG_ATTACH t
60−
61−type TagAttachT t = TaggedTrans (TAG_ATTACH t) IdentityT
62−
63−-- | Attach a tag to untagged transformers.
64−tagAttach :: forall tag m a . TagAttachT tag m a -> m a
65−tagAttach = coerce (runIdentityT @_ @m @a)
66−
67−instance {-# OVERLAPPING #-}
68− ( MonadReader tag r m, trans ~ IdentityT
69− ) => Mtl.MonadReader r (TaggedTrans (TAG_ATTACH tag) trans m)
70− where
71− ask = ask @tag
72− local = local @tag
73− reader = reader @tag
74−
75−instance {-# OVERLAPPING #-}
76− ( MonadState tag s m, trans ~ IdentityT
77− ) => Mtl.MonadState s (TaggedTrans (TAG_ATTACH tag) trans m)
78− where
79− get = get @tag
80− put = put @tag
81− state = state @tag
82−
83−instance {-# OVERLAPPING #-}
84− ( MonadExcept tag e m, trans ~ IdentityT
85− ) => Mtl.MonadError e (TaggedTrans (TAG_ATTACH tag) trans m)
86− where
87− throwError = throw @tag
88− catchError = catch @tag
89−
90−instance {-# OVERLAPPING #-}
91− ( MonadWriter tag w m, trans ~ IdentityT
92− ) => Mtl.MonadWriter w (TaggedTrans (TAG_ATTACH tag) trans m)
93− where
94− writer = writer @tag
95− tell = tell @tag
96− listen = listen @tag
97− pass = pass @tag
98−
99−-- | Encode type-level information for 'tagReplace'.
100−data TAG_REPLACE tOld tNew
101−
102−type TagReplaceT tOld tNew = TaggedTrans (TAG_REPLACE tOld tNew) IdentityT
103−
104−-- | Replace a tag with another tag.
105−tagReplace :: forall tOld tNew m a . TagReplaceT tOld tNew m a -> m a
106−tagReplace = coerce (runIdentityT @_ @m @a)
107−
108−instance
109− ( MonadReader tNew r m, trans ~ IdentityT
110− ) => MonadReader tOld r (TaggedTrans (TAG_REPLACE tOld tNew) trans m)
111− where
112− ask = ask @tNew
113− local = local @tNew
114− reader = reader @tNew
115−
116−instance
117− ( MonadState tNew s m, trans ~ IdentityT
118− ) => MonadState tOld s (TaggedTrans (TAG_REPLACE tOld tNew) trans m)
119− where
120− get = get @tNew
121− put = put @tNew
122− state = state @tNew
123−
124−instance
125− ( MonadExcept tNew e m, trans ~ IdentityT
126− ) => MonadExcept tOld e (TaggedTrans (TAG_REPLACE tOld tNew) trans m)
127− where
128− throw = throw @tNew
129− catch = catch @tNew
130−
131−instance
132− ( MonadWriter tNew w m, trans ~ IdentityT
133− ) => MonadWriter tOld w (TaggedTrans (TAG_REPLACE tOld tNew) trans m)
134− where
135− writer = writer @tNew
136− tell = tell @tNew
137− listen = listen @tNew
138− pass = pass @tNew
src/Ether/TaggedTrans.hsdeleted−206
@@ -1,206 +0,0 @@
1−-- The use of ImpredicativeTypes here is safe, see discussion under GitHub issue
2−-- #35. It's only needed to allow the visible type application of a polytype.
3−{-# LANGUAGE ImpredicativeTypes #-}
4−
5−module Ether.TaggedTrans
6− ( TaggedTrans(..)
7− ) where
8−
9−import Control.Applicative
10−import Control.Monad (MonadPlus)
11−import Control.Monad.Fix (MonadFix)
12−import Control.Monad.Trans.Class (MonadTrans, lift)
13−import Control.Monad.IO.Class (MonadIO)
14−import Control.Monad.Morph (MFunctor(..), MMonad(..))
15−import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
16−
17−import qualified Control.Monad.Base as MB
18−import qualified Control.Monad.Trans.Control as MC
19−
20−import qualified Control.Monad.Trans.Lift.StT as Lift
21−import qualified Control.Monad.Trans.Lift.Local as Lift
22−import qualified Control.Monad.Trans.Lift.Catch as Lift
23−import qualified Control.Monad.Trans.Lift.Listen as Lift
24−import qualified Control.Monad.Trans.Lift.Pass as Lift
25−import qualified Control.Monad.Trans.Lift.CallCC as Lift
26−
27−import qualified Control.Monad.Cont.Class as Mtl
28−import qualified Control.Monad.Reader.Class as Mtl
29−import qualified Control.Monad.State.Class as Mtl
30−import qualified Control.Monad.Writer.Class as Mtl
31−import qualified Control.Monad.Error.Class as Mtl
32−
33−import GHC.Generics (Generic)
34−import Data.Coerce (coerce)
35−
36−newtype TaggedTrans tag trans m a = TaggedTrans (trans m a)
37− deriving
38− ( Generic
39− , Functor, Applicative, Alternative, Monad, MonadPlus
40− , MonadFix, MonadTrans, MonadIO
41− , MonadThrow, MonadCatch, MonadMask )
42−
43−type Pack tag trans m a = trans m a -> TaggedTrans tag trans m a
44−
45−type Unpack tag trans m a = TaggedTrans tag trans m a -> trans m a
46−
47−instance
48− ( MB.MonadBase b (trans m)
49− ) => MB.MonadBase b (TaggedTrans tag trans m)
50− where
51− liftBase =
52− (coerce :: forall a .
53− (b a -> trans m a) ->
54− (b a -> TaggedTrans tag trans m a))
55− MB.liftBase
56−
57−instance
58− ( MC.MonadTransControl trans
59− ) => MC.MonadTransControl (TaggedTrans tag trans)
60− where
61− type StT (TaggedTrans tag trans) a = MC.StT trans a
62−
63− liftWith = MC.defaultLiftWith
64− (coerce :: Pack tag trans m a)
65− (coerce :: Unpack tag trans m a)
66−
67− restoreT = MC.defaultRestoreT
68− (coerce :: Pack tag trans m a)
69−
70−type LiftBaseWith b m a = (MC.RunInBase m b -> b a) -> m a
71−
72−newtype LiftBaseWith' b m a = LBW { unLBW :: LiftBaseWith b m a }
73−
74−coerceLiftBaseWith ::
75− LiftBaseWith b (trans m) a ->
76− LiftBaseWith b (TaggedTrans tag trans m) a
77−coerceLiftBaseWith lbw =
78− unLBW (coerce (LBW lbw))
79−
80−instance
81− ( MC.MonadBaseControl b (trans m)
82− ) => MC.MonadBaseControl b (TaggedTrans tag trans m)
83− where
84− type StM (TaggedTrans tag trans m) a = MC.StM (trans m) a
85−
86− liftBaseWith = coerceLiftBaseWith MC.liftBaseWith
87−
88− restoreM =
89− (coerce :: forall a .
90− (MC.StM (trans m) a -> trans m a) ->
91− (MC.StM (trans m) a -> TaggedTrans tag trans m a))
92− MC.restoreM
93−
94−type instance Lift.StT (TaggedTrans tag trans) a = Lift.StT trans a
95−
96−instance Lift.LiftLocal trans => Lift.LiftLocal (TaggedTrans tag trans) where
97− liftLocal =
98− Lift.defaultLiftLocal
99− (coerce :: Pack tag trans m a)
100− (coerce :: Unpack tag trans m a)
101−
102−instance Lift.LiftCatch trans => Lift.LiftCatch (TaggedTrans tag trans) where
103− liftCatch =
104− Lift.defaultLiftCatch
105− (coerce :: Pack tag trans m a)
106− (coerce :: Unpack tag trans m a)
107−
108−instance Lift.LiftListen trans => Lift.LiftListen (TaggedTrans tag trans) where
109− liftListen =
110− Lift.defaultLiftListen
111− (coerce :: Pack tag trans m a)
112− (coerce :: Unpack tag trans m a)
113−
114−instance Lift.LiftPass trans => Lift.LiftPass (TaggedTrans tag trans) where
115− liftPass =
116− Lift.defaultLiftPass
117− (coerce :: Pack tag trans m a)
118− (coerce :: Unpack tag trans m a)
119−
120−instance Lift.LiftCallCC trans => Lift.LiftCallCC (TaggedTrans tag trans) where
121− liftCallCC =
122− Lift.defaultLiftCallCC
123− (coerce :: Pack tag trans m a)
124− (coerce :: Unpack tag trans m a)
125− liftCallCC' =
126− Lift.defaultLiftCallCC'
127− (coerce :: Pack tag trans m a)
128− (coerce :: Unpack tag trans m a)
129−
130−
131−-- Instances for mtl classes
132−
133−instance
134− ( Mtl.MonadCont m
135− , Lift.LiftCallCC trans
136− , Monad (trans m)
137− ) => Mtl.MonadCont (TaggedTrans tag trans m)
138− where
139− callCC = Lift.liftCallCC' Mtl.callCC
140−
141−instance
142− ( Mtl.MonadReader r m
143− , Lift.LiftLocal trans
144− , Monad (trans m)
145− ) => Mtl.MonadReader r (TaggedTrans tag trans m)
146− where
147− ask = lift Mtl.ask
148− local = Lift.liftLocal Mtl.ask Mtl.local
149− reader = lift . Mtl.reader
150−
151−instance
152− ( Mtl.MonadState s m
153− , MonadTrans trans
154− , Monad (trans m)
155− ) => Mtl.MonadState s (TaggedTrans tag trans m)
156− where
157− get = lift Mtl.get
158− put = lift . Mtl.put
159− state = lift . Mtl.state
160−
161−instance
162− ( Mtl.MonadWriter w m
163− , Lift.LiftListen trans
164− , Lift.LiftPass trans
165− , Monad (trans m)
166− ) => Mtl.MonadWriter w (TaggedTrans tag trans m)
167− where
168− writer = lift . Mtl.writer
169− tell = lift . Mtl.tell
170− listen = Lift.liftListen Mtl.listen
171− pass = Lift.liftPass Mtl.pass
172−
173−instance
174− ( Mtl.MonadError e m
175− , Lift.LiftCatch trans
176− , Monad (trans m)
177− ) => Mtl.MonadError e (TaggedTrans tag trans m)
178− where
179− throwError = lift . Mtl.throwError
180− catchError = Lift.liftCatch Mtl.catchError
181−
182−type Hoist trans =
183− forall m n b . Monad m =>
184− (forall a . m a -> n a) -> trans m b -> trans n b
185−
186−-- NB: Don't use GeneralizedNewtypeDeriving to create this instance, as it will
187−-- trigger GHC Trac #11837 on GHC 8.0.1 and older.
188−instance MFunctor trans => MFunctor (TaggedTrans tag trans) where
189− hoist =
190− coerce
191− @(Hoist trans)
192− @(Hoist (TaggedTrans tag trans))
193− hoist
194−
195−type Embed trans =
196− forall n m b . Monad n =>
197− (forall a . m a -> trans n a) -> trans m b -> trans n b
198−
199−-- NB: Don't use GeneralizedNewtypeDeriving to create this instance, as it will
200−-- trigger GHC Trac #11837 on GHC 8.0.1 and older.
201−instance MMonad trans => MMonad (TaggedTrans tag trans) where
202− embed =
203− coerce
204− @(Embed trans)
205− @(Embed (TaggedTrans tag trans))
206− embed
src/Ether/Writer.hsdeleted−287
@@ -1,287 +0,0 @@
1−module Ether.Writer
2− (
3− -- * MonadWriter class
4− MonadWriter
5− , writer
6− , tell
7− , listen
8− , pass
9− , listens
10− , censor
11− -- * The Writer monad
12− , Writer
13− , runWriter
14− , execWriter
15− -- * The WriterT monad transformer
16− , WriterT
17− , writerT
18− , runWriterT
19− , execWriterT
20− -- * The Writer monad (lazy)
21− , LazyWriter
22− , runLazyWriter
23− , execLazyWriter
24− -- * The WriterT monad transformer (lazy)
25− , LazyWriterT
26− , lazyWriterT
27− , runLazyWriterT
28− , execLazyWriterT
29− -- * MonadWriter class (implicit)
30− , MonadWriter'
31− , writer'
32− , tell'
33− , listen'
34− , pass'
35− , listens'
36− , censor'
37− -- * The Writer monad (implicit)
38− , Writer'
39− , runWriter'
40− , execWriter'
41− -- * The WriterT monad transformer (implicit)
42− , WriterT'
43− , writerT'
44− , runWriterT'
45− , execWriterT'
46− -- * The Writer monad (lazy, implicit)
47− , LazyWriter'
48− , runLazyWriter'
49− , execLazyWriter'
50− -- * The WriterT monad transformer (lazy, implicit)
51− , LazyWriterT'
52− , lazyWriterT'
53− , runLazyWriterT'
54− , execLazyWriterT'
55− -- * Internal labels
56− , TAGGED
57− , WRITER
58− ) where
59−
60−import Control.Monad.Signatures (Listen, Pass)
61−import qualified Control.Monad.Trans.Lift.Listen as Lift
62−import qualified Control.Monad.Trans.Lift.Pass as Lift
63−import qualified Control.Monad.Writer.Class as T
64−import qualified Control.Monad.Writer.CPS as T.CPS
65−import qualified Control.Monad.Writer.Lazy as T.Lazy
66−import Data.Coerce
67−import Data.Functor.Identity
68−
69−import Ether.Internal
70−import Ether.TaggedTrans
71−
72−class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where
73−
74− {-# MINIMAL (writer | tell), listen, pass #-}
75−
76− -- | Embed a simple writer action.
77− writer :: (a, w) -> m a
78− writer ~(a, w) = a <$ tell @tag w
79−
80− -- | Append a value to the accumulator within the monad.
81− tell :: w -> m ()
82− tell w = writer @tag ((),w)
83−
84− -- | Execute an action and add its accumulator
85− -- to the value of the computation.
86− listen :: m a -> m (a, w)
87−
88− -- | Execute an action which returns a value and a function,
89− -- and return the value, applying the function to the accumulator.
90− pass :: m (a, w -> w) -> m a
91−
92−instance {-# OVERLAPPABLE #-}
93− ( Lift.LiftListen t
94− , Lift.LiftPass t
95− , Monad (t m)
96− , MonadWriter tag w m
97− , Monoid w
98− ) => MonadWriter tag w (t m) where
99− writer = Lift.lift . writer @tag
100− tell = Lift.lift . tell @tag
101− listen = Lift.liftListen (listen @tag)
102− pass = Lift.liftPass (pass @tag)
103−
104−-- | Execute an action and add the result of applying the given function to
105−-- its accumulator to the value of the computation.
106−listens :: forall tag w m a b . MonadWriter tag w m => (w -> b) -> m a -> m (a, b)
107−listens f m = do
108− ~(a, w) <- listen @tag m
109− return (a, f w)
110−
111−-- | Execute an action and apply a function to its accumulator.
112−censor :: forall tag w m a . MonadWriter tag w m => (w -> w) -> m a -> m a
113−censor f m = pass @tag $ do
114− a <- m
115− return (a, f)
116−
117−-- | Encode type-level information for 'WriterT'.
118−data WRITER
119−
120−type instance HandleSuper WRITER w trans = Monoid w
121−type instance HandleConstraint WRITER w trans m =
122− T.MonadWriter w (trans m)
123−
124−instance Monoid w => Handle WRITER w (T.CPS.WriterT w) where
125− handling r = r
126−
127−instance Monoid w => Handle WRITER w (T.Lazy.WriterT w) where
128− handling r = r
129−
130−instance
131− ( Handle WRITER w trans
132− , Monad m, Monad (trans m)
133− ) => MonadWriter tag w (TaggedTrans (TAGGED WRITER tag) trans m)
134− where
135−
136− writer =
137− handling @WRITER @w @trans @m $
138− coerce (T.writer @w @(trans m) @a) ::
139− forall eff a . (a, w) -> TaggedTrans eff trans m a
140−
141− tell =
142− handling @WRITER @w @trans @m $
143− coerce (T.tell @w @(trans m))
144−
145− listen =
146− handling @WRITER @w @trans @m $
147− coerce (T.listen @w @(trans m) @a) ::
148− forall eff a . Listen w (TaggedTrans eff trans m) a
149−
150− pass =
151− handling @WRITER @w @trans @m $
152− coerce (T.pass @w @(trans m) @a) ::
153− forall eff a . Pass w (TaggedTrans eff trans m) a
154−
155−-- | The parametrizable writer monad.
156−--
157−-- Computations can accumulate a monoid value.
158−--
159−-- The 'return' function produces the output 'mempty', while '>>=' combines
160−-- the outputs of the subcomputations using 'mappend'.
161−type Writer tag w = WriterT tag w Identity
162−
163−-- | The writer monad transformer.
164−--
165−-- The 'return' function produces the output 'mempty', while '>>=' combines
166−-- the outputs of the subcomputations using 'mappend'.
167−type WriterT tag w = TaggedTrans (TAGGED WRITER tag) (T.CPS.WriterT w)
168−
169−-- | Constructor for computations in the writer monad transformer.
170−writerT :: forall tag w m a . (Functor m, Monoid w) => m (a, w) -> WriterT tag w m a
171−writerT = coerce (T.CPS.writerT @m @w @a)
172−
173−-- | Runs a 'WriterT' and returns both the normal value
174−-- and the final accumulator.
175−runWriterT :: forall tag w m a . Monoid w => WriterT tag w m a -> m (a, w)
176−runWriterT = coerce (T.CPS.runWriterT @w @m @a)
177−
178−-- | Runs a 'Writer' and returns both the normal value
179−-- and the final accumulator.
180−runWriter :: forall tag w a . Monoid w => Writer tag w a -> (a, w)
181−runWriter = coerce (T.CPS.runWriter @w @a)
182−
183−-- | Runs a 'WriterT' and returns the final accumulator,
184−-- discarding the normal value.
185−execWriterT :: forall tag w m a . (Monad m, Monoid w) => WriterT tag w m a -> m w
186−execWriterT = coerce (T.CPS.execWriterT @m @w @a)
187−
188−-- | Runs a 'Writer' and returns the final accumulator,
189−-- discarding the normal value.
190−execWriter :: forall tag w a . Monoid w => Writer tag w a -> w
191−execWriter = coerce (T.CPS.execWriter @w @a)
192−
193−-- | The parametrizable writer monad.
194−--
195−-- Computations can accumulate a monoid value.
196−--
197−-- The 'return' function produces the output 'mempty', while '>>=' combines
198−-- the outputs of the subcomputations using 'mappend'.
199−type LazyWriter tag w = LazyWriterT tag w Identity
200−
201−-- | The writer monad transformer.
202−--
203−-- The 'return' function produces the output 'mempty', while '>>=' combines
204−-- the outputs of the subcomputations using 'mappend'.
205−type LazyWriterT tag w = TaggedTrans (TAGGED WRITER tag) (T.Lazy.WriterT w)
206−
207−-- | Constructor for computations in the writer monad transformer.
208−lazyWriterT :: forall tag w m a . m (a, w) -> LazyWriterT tag w m a
209−lazyWriterT = coerce (T.Lazy.WriterT @w @m @a)
210−
211−-- | Runs a 'WriterT' and returns both the normal value
212−-- and the final accumulator.
213−runLazyWriterT :: forall tag w m a . LazyWriterT tag w m a -> m (a, w)
214−runLazyWriterT = coerce (T.Lazy.runWriterT @w @m @a)
215−
216−-- | Runs a 'Writer' and returns both the normal value
217−-- and the final accumulator.
218−runLazyWriter :: forall tag w a . LazyWriter tag w a -> (a, w)
219−runLazyWriter = coerce (T.Lazy.runWriter @w @a)
220−
221−-- | Runs a 'WriterT' and returns the final accumulator,
222−-- discarding the normal value.
223−execLazyWriterT :: forall tag w m a . Monad m => LazyWriterT tag w m a -> m w
224−execLazyWriterT = coerce (T.Lazy.execWriterT @m @w @a)
225−
226−-- | Runs a 'Writer' and returns the final accumulator,
227−-- discarding the normal value.
228−execLazyWriter :: forall tag w a . LazyWriter tag w a -> w
229−execLazyWriter = coerce (T.Lazy.execWriter @w @a)
230−
231−type Writer' w = Writer w w
232−
233−runWriter' :: Monoid w => Writer' w a -> (a, w)
234−runWriter' = runWriter
235−
236−execWriter' :: Monoid w => Writer' w a -> w
237−execWriter' = execWriter
238−
239−type WriterT' w = WriterT w w
240−
241−writerT' :: (Functor m, Monoid w) => m (a, w) -> WriterT' w m a
242−writerT' = writerT
243−
244−runWriterT' :: Monoid w => WriterT' w m a -> m (a, w)
245−runWriterT' = runWriterT
246−
247−execWriterT' :: (Monad m, Monoid w) => WriterT' w m a -> m w
248−execWriterT' = execWriterT
249−
250−type LazyWriter' w = LazyWriter w w
251−
252−runLazyWriter' :: LazyWriter' w a -> (a, w)
253−runLazyWriter' = runLazyWriter
254−
255−execLazyWriter' :: LazyWriter' w a -> w
256−execLazyWriter' = execLazyWriter
257−
258−type LazyWriterT' w = LazyWriterT w w
259−
260−lazyWriterT' :: m (a, w) -> LazyWriterT' w m a
261−lazyWriterT' = lazyWriterT
262−
263−runLazyWriterT' :: LazyWriterT' w m a -> m (a, w)
264−runLazyWriterT' = runLazyWriterT
265−
266−execLazyWriterT' :: Monad m => LazyWriterT' w m a -> m w
267−execLazyWriterT' = execLazyWriterT
268−
269−type MonadWriter' w = MonadWriter w w
270−
271−writer' :: forall w m a . MonadWriter' w m => (a, w) -> m a
272−writer' = writer @w
273−
274−tell' :: forall w m . MonadWriter' w m => w -> m ()
275−tell' = tell @w
276−
277−listen' :: forall w m a . MonadWriter' w m => m a -> m (a, w)
278−listen' = listen @w
279−
280−pass' :: forall w m a . MonadWriter' w m => m (a, w -> w) -> m a
281−pass' = pass @w
282−
283−listens' :: forall w m a b . MonadWriter' w m => (w -> b) -> m a -> m (a, b)
284−listens' = listens @w
285−
286−censor' :: forall w m a . MonadWriter' w m => (w -> w) -> m a -> m a
287−censor' = censor @w
stack.yamlnew file+84
@@ -0,0 +1,84 @@
1+compiler-check: match-exact
2+resolver: ghc-8.0.0.20160421
3+setup-info:
4+ ghc:
5+ linux64:
6+ 8.0.0.20160421:
7+ url: https://downloads.haskell.org/~ghc/8.0.1-rc4/ghc-8.0.0.20160421-x86_64-unknown-linux.tar.xz
8+
9+packages:
10+- 'ether'
11+- 'ether-flatten'
12+- 'ether-zoom'
13+- 'ether-suite'
14+
15+extra-deps:
16+- Glob-0.7.5
17+- QuickCheck-2.8.2
18+- StateVar-1.1.0.4
19+- abstract-deque-0.3
20+- abstract-par-0.3.3
21+- adjunctions-4.3
22+- aeson-0.11.2.0
23+- ansi-terminal-0.6.2.3
24+- ansi-wl-pprint-0.6.7.3
25+- async-2.1.0
26+- attoparsec-0.13.0.2
27+- base-orphans-0.5.4
28+- bifunctors-5.3
29+- blaze-builder-0.4.0.2
30+- cassava-0.4.5.0
31+- cereal-0.5.1.0
32+- clock-0.7.2
33+- comonad-5
34+- contravariant-1.4
35+- criterion-1.1.1.0
36+- distributive-0.5.0.2
37+- dlist-0.7.1.2
38+- erf-2.0.0.0
39+- exceptions-0.8.2.1
40+- fail-4.9.0.0
41+- free-4.12.4
42+- hashable-1.2.4.0
43+- hastache-0.6.1
44+- ieee754-0.7.8
45+- kan-extensions-5.0.1
46+- lens-4.14
47+- math-functions-0.1.6.0
48+- mmorph-1.0.6
49+- monad-control-1.0.1.0
50+- monad-par-0.3.4.7
51+- monad-par-extras-0.3.3
52+- mtl-2.2.1
53+- mwc-random-0.13.4.0
54+- optparse-applicative-0.12.1.0
55+- parallel-3.2.1.0
56+- parsec-3.1.9
57+- prelude-extras-0.4.0.3
58+- primitive-0.6.1.0
59+- profunctors-5.2
60+- random-1.1
61+- reflection-2.1.2
62+- regex-base-0.93.2
63+- regex-tdfa-1.2.2
64+- scientific-0.3.4.6
65+- semigroupoids-5.0.1
66+- semigroups-0.18.1
67+- statistics-0.13.2.3
68+- stm-2.4.4.1
69+- syb-0.6
70+- tagged-0.8.4
71+- tasty-0.11.0.3
72+- tasty-quickcheck-0.8.4
73+- text-1.2.2.1
74+- tf-random-0.5
75+- transformers-base-0.4.4
76+- transformers-compat-0.5.1.4
77+- transformers-lift-0.1.0.1
78+- unbounded-delays-0.1.0.9
79+- unordered-containers-0.2.7.0
80+- vector-0.11.0.0
81+- vector-algorithms-0.7.0.1
82+- vector-binary-instances-0.2.3.2
83+- vector-th-unbox-0.2.1.6
84+- void-0.7.1
test/TupleInstances.hsdeleted−9
@@ -1,9 +0,0 @@
1−{-# OPTIONS -fno-warn-orphans #-}
2−{-# LANGUAGE CPP #-}
3−
4−module TupleInstances () where
5−
6−#ifdef DISABLE_TUP_INSTANCES
7−import Ether.Internal (makeTupleInstancesHasLens)
8−makeTupleInstancesHasLens [2]
9−#endif