on master help sign in
Merge pull request #22 from int-index/amb-default

Ambiguous combinators as default

commit0140749d17bd92f55a8f2351a92a671542579481 authorIndex Int <vlad.z.4096@gmail.com> dateSat 30 Apr 2016, 20:42 (10 years ago) parent4c7619a3521eac
36 files changed+303−609
ether.cabal+6−11 src/Control/Monad/Ether/Ambiguous.hs−13 src/Control/Monad/Ether/Ambiguous/Except.hs−55 src/Control/Monad/Ether/Ambiguous/Reader.hs−54 src/Control/Monad/Ether/Ambiguous/State.hs−8 src/Control/Monad/Ether/Ambiguous/State/Lazy.hs−79 src/Control/Monad/Ether/Ambiguous/State/Strict.hs−79 src/Control/Monad/Ether/Ambiguous/Writer.hs−74 src/Control/Monad/Ether/Except.hs+20−7 src/Control/Monad/Ether/Except/Class.hs+4−7 src/Control/Monad/Ether/Implicit/Except.hs+1−3 src/Control/Monad/Ether/Implicit/Reader.hs+1−3 src/Control/Monad/Ether/Implicit/State/Lazy.hs+1−3 src/Control/Monad/Ether/Implicit/State/Strict.hs+1−3 src/Control/Monad/Ether/Implicit/Writer.hs+1−3 src/Control/Monad/Ether/Reader.hs+42−2 src/Control/Monad/Ether/Reader/Class.hs+5−18 src/Control/Monad/Ether/State/Class.hs+8−21 src/Control/Monad/Ether/State/Common.hs+35 src/Control/Monad/Ether/State/Lazy.hs+5−2 src/Control/Monad/Ether/State/Strict.hs+5−2 src/Control/Monad/Ether/Writer.hs+41−2 src/Control/Monad/Ether/Writer/Class.hs+6−24 src/Control/Monad/Trans/Ether/Dispatch.hs+25−25 src/Control/Monad/Trans/Ether/Except.hs+15−16 src/Control/Monad/Trans/Ether/Reader.hs+14−17 src/Control/Monad/Trans/Ether/State/Lazy.hs+21−24 src/Control/Monad/Trans/Ether/State/Strict.hs+21−24 src/Control/Monad/Trans/Ether/Tagged.hs−2 src/Control/Monad/Trans/Ether/Writer.hs+19−22 test/Regression/T1.hs+1−1 test/Regression/T3.hs+1−1 test/Regression/T4.hs+1−1 test/Regression/T7.hs+1−1 test/Regression/T8.hs+1−1 test/Regression/T9.hs+1−1
ether.cabal+6−11
@@ -54,13 +54,8 @@ library
5454 Control.Monad.Ether.Implicit.State.Lazy
5555 Control.Monad.Ether.Implicit.State.Strict
5656 Control.Monad.Ether.Implicit.Except
57− Control.Monad.Ether.Ambiguous
58− Control.Monad.Ether.Ambiguous.Reader
59− Control.Monad.Ether.Ambiguous.Writer
60− Control.Monad.Ether.Ambiguous.State
61− Control.Monad.Ether.Ambiguous.State.Lazy
62− Control.Monad.Ether.Ambiguous.State.Strict
63− Control.Monad.Ether.Ambiguous.Except
57+
58+ other-modules: Control.Monad.Ether.State.Common
6459
6560 build-depends: base >=4.7 && <4.10
6661 , transformers >=0.4.2
@@ -74,17 +69,17 @@ library
7469 , ghc-prim >=0.3
7570
7671 default-language: Haskell2010
72+ default-extensions: PolyKinds
73+ ScopedTypeVariables
74+ FunctionalDependencies
75+ TypeApplications
7776 other-extensions: ConstraintKinds
7877 DataKinds
7978 DefaultSignatures
8079 DeriveGeneric
8180 FlexibleInstances
82− FunctionalDependencies
8381 GeneralizedNewtypeDeriving
8482 MagicHash
85− MultiParamTypeClasses
86− ScopedTypeVariables
87− TypeApplications
8883 TypeFamilies
8984 TypeOperators
9085 UndecidableInstances
src/Control/Monad/Ether/Ambiguous.hsdeleted−13
@@ -1,13 +0,0 @@
1−
2−-- | This module provides convenience exports of all
3−-- ambiguously tagged monad classes from Ether.
4−
5−module Control.Monad.Ether.Ambiguous (module X) where
6−
7−import Control.Monad as X
8−import Control.Monad.Fix as X
9−import Control.Monad.Ether.Ambiguous.Reader as X
10−import Control.Monad.Ether.Ambiguous.Writer as X
11−import Control.Monad.Ether.Ambiguous.State as X
12−import Control.Monad.Ether.Ambiguous.Except as X
13−import Control.Monad.Trans.Ether.Dispatch as X
src/Control/Monad/Ether/Ambiguous/Except.hsdeleted−55
@@ -1,55 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.Except".
6−
7−module Control.Monad.Ether.Ambiguous.Except
8− (
9− -- * MonadExcept class
10− MonadExcept
11− , throw
12− , catch
13− -- * The Except monad
14− , Except
15− , runExcept
16− -- * The ExceptT monad transformer
17− , ExceptT
18− , exceptT
19− , runExceptT
20− -- * Handle functions
21− , handle
22− , handleT
23− ) where
24−
25−import GHC.Prim (Proxy#, proxy#)
26−import Control.Monad.Ether.Except (MonadExcept, ExceptT, Except)
27−import qualified Control.Monad.Ether.Except as Explicit
28−
29−-- | See 'Control.Monad.Ether.Except.throw'.
30−throw :: forall tag e m a . MonadExcept tag e m => e -> m a
31−throw = Explicit.throw (proxy# :: Proxy# tag)
32−
33−-- | See 'Control.Monad.Ether.Except.catch'.
34−catch :: forall tag e m a . MonadExcept tag e m => m a -> (e -> m a) -> m a
35−catch = Explicit.catch (proxy# :: Proxy# tag)
36−
37−-- | See 'Control.Monad.Ether.Except.runExcept'.
38−runExcept :: forall tag e a . Except tag e a -> Either e a
39−runExcept = Explicit.runExcept proxy#
40−
41−-- | See 'Control.Monad.Ether.Except.exceptT'.
42−exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
43−exceptT = Explicit.exceptT proxy#
44−
45−-- | See 'Control.Monad.Ether.Except.runExceptT'.
46−runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
47−runExceptT = Explicit.runExceptT proxy#
48−
49−-- | See 'Control.Monad.Ether.Except.handle'.
50−handle :: forall tag e a . (e -> a) -> Except tag e a -> a
51−handle = Explicit.handle proxy#
52−
53−-- | See 'Control.Monad.Ether.Except.handleT'.
54−handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
55−handleT = Explicit.handleT proxy#
src/Control/Monad/Ether/Ambiguous/Reader.hsdeleted−54
@@ -1,54 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.Reader".
6−
7−module Control.Monad.Ether.Ambiguous.Reader
8− (
9− -- * MonadReader class
10− MonadReader
11− , local
12− , ask
13− , reader
14− , asks
15− -- * The Reader monad
16− , Reader
17− , runReader
18− -- * The ReaderT monad transformer
19− , ReaderT
20− , readerT
21− , runReaderT
22− ) where
23−
24−import GHC.Prim (Proxy#, proxy#)
25−import Control.Monad.Ether.Reader (MonadReader, ReaderT, Reader)
26−import qualified Control.Monad.Ether.Reader as Explicit
27−
28−-- | See 'Control.Monad.Ether.Reader.readerT'.
29−readerT :: forall tag r m a . (r -> m a) -> ReaderT tag r m a
30−readerT = Explicit.readerT proxy#
31−
32−-- | See 'Control.Monad.Ether.Reader.runReaderT'.
33−runReaderT :: forall tag r m a . ReaderT tag r m a -> r -> m a
34−runReaderT = Explicit.runReaderT proxy#
35−
36−-- | See 'Control.Monad.Ether.Reader.runReader'.
37−runReader :: forall tag r a . Reader tag r a -> r -> a
38−runReader = Explicit.runReader proxy#
39−
40−-- | See 'Control.Monad.Ether.Reader.local'.
41−local :: forall tag r m a . MonadReader tag r m => (r -> r) -> m a -> m a
42−local = Explicit.local (proxy# :: Proxy# tag)
43−
44−-- | See 'Control.Monad.Ether.Reader.ask'.
45−ask :: forall tag r m . MonadReader tag r m => m r
46−ask = Explicit.ask (proxy# :: Proxy# tag)
47−
48−-- | See 'Control.Monad.Ether.Reader.reader'.
49−reader :: forall tag r m a . MonadReader tag r m => (r -> a) -> m a
50−reader = Explicit.reader (proxy# :: Proxy# tag)
51−
52−-- | See 'Control.Monad.Ether.Reader.asks'.
53−asks :: forall tag r m a . MonadReader tag r m => (r -> a) -> m a
54−asks = Explicit.asks (proxy# :: Proxy# tag)
src/Control/Monad/Ether/Ambiguous/State.hsdeleted−8
@@ -1,8 +0,0 @@
1−
2−-- | See "Control.Monad.Ether.State".
3−
4−module Control.Monad.Ether.Ambiguous.State
5− ( module Control.Monad.Ether.Ambiguous.State.Lazy
6− ) where
7−
8−import Control.Monad.Ether.Ambiguous.State.Lazy
src/Control/Monad/Ether/Ambiguous/State/Lazy.hsdeleted−79
@@ -1,79 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.State.Lazy".
6−
7−module Control.Monad.Ether.Ambiguous.State.Lazy
8− (
9− -- * MonadState class
10− MonadState
11− , get
12− , put
13− , state
14− , modify
15− , gets
16− -- * The State monad
17− , State
18− , runState
19− , evalState
20− , execState
21− -- * The StateT monad transformer
22− , StateT
23− , stateT
24− , runStateT
25− , evalStateT
26− , execStateT
27− ) where
28−
29−import GHC.Prim (Proxy#, proxy#)
30−import Control.Monad.Ether.State.Lazy (MonadState, StateT, State)
31−import qualified Control.Monad.Ether.State.Lazy as Explicit
32−
33−-- | See 'Control.Monad.Ether.State.Lazy.stateT'.
34−stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
35−stateT = Explicit.stateT proxy#
36−
37−-- | See 'Control.Monad.Ether.State.Lazy.runStateT'.
38−runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
39−runStateT = Explicit.runStateT proxy#
40−
41−-- | See 'Control.Monad.Ether.State.Lazy.runState'.
42−runState :: forall tag s a . State tag s a -> s -> (a, s)
43−runState = Explicit.runState proxy#
44−
45−-- | See 'Control.Monad.Ether.State.Lazy.evalStateT'.
46−evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
47−evalStateT = Explicit.evalStateT proxy#
48−
49−-- | See 'Control.Monad.Ether.State.Lazy.evalState'.
50−evalState :: forall tag s a . State tag s a -> s -> a
51−evalState = Explicit.evalState proxy#
52−
53−-- | See 'Control.Monad.Ether.State.Lazy.execStateT'.
54−execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
55−execStateT = Explicit.execStateT proxy#
56−
57−-- | See 'Control.Monad.Ether.State.Lazy.execState'.
58−execState :: forall tag s a . State tag s a -> s -> s
59−execState = Explicit.execState proxy#
60−
61−-- | See 'Control.Monad.Ether.State.Lazy.get'.
62−get :: forall tag s m . MonadState tag s m => m s
63−get = Explicit.get (proxy# :: Proxy# tag)
64−
65−-- | See 'Control.Monad.Ether.State.Lazy.gets'.
66−gets :: forall tag s m a . MonadState tag s m => (s -> a) -> m a
67−gets = Explicit.gets (proxy# :: Proxy# tag)
68−
69−-- | See 'Control.Monad.Ether.State.Lazy.put'.
70−put :: forall tag s m . MonadState tag s m => s -> m ()
71−put = Explicit.put (proxy# :: Proxy# tag)
72−
73−-- | See 'Control.Monad.Ether.State.Lazy.state'.
74−state :: forall tag s m a . MonadState tag s m => (s -> (a, s)) -> m a
75−state = Explicit.state (proxy# :: Proxy# tag)
76−
77−-- | See 'Control.Monad.Ether.State.Lazy.modify'.
78−modify :: forall tag s m . MonadState tag s m => (s -> s) -> m ()
79−modify = Explicit.modify (proxy# :: Proxy# tag)
src/Control/Monad/Ether/Ambiguous/State/Strict.hsdeleted−79
@@ -1,79 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.State.Strict".
6−
7−module Control.Monad.Ether.Ambiguous.State.Strict
8− (
9− -- * MonadState class
10− MonadState
11− , get
12− , put
13− , state
14− , modify
15− , gets
16− -- * The State monad
17− , State
18− , runState
19− , evalState
20− , execState
21− -- * The StateT monad transformer
22− , StateT
23− , stateT
24− , runStateT
25− , evalStateT
26− , execStateT
27− ) where
28−
29−import GHC.Prim (Proxy#, proxy#)
30−import Control.Monad.Ether.State.Strict (MonadState, StateT, State)
31−import qualified Control.Monad.Ether.State.Strict as Explicit
32−
33−-- | See 'Control.Monad.Ether.State.Strict.stateT'.
34−stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
35−stateT = Explicit.stateT proxy#
36−
37−-- | See 'Control.Monad.Ether.State.Strict.runStateT'.
38−runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
39−runStateT = Explicit.runStateT proxy#
40−
41−-- | See 'Control.Monad.Ether.State.Strict.runState'.
42−runState :: forall tag s a . State tag s a -> s -> (a, s)
43−runState = Explicit.runState proxy#
44−
45−-- | See 'Control.Monad.Ether.State.Strict.evalStateT'.
46−evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
47−evalStateT = Explicit.evalStateT proxy#
48−
49−-- | See 'Control.Monad.Ether.State.Strict.evalState'.
50−evalState :: forall tag s a . State tag s a -> s -> a
51−evalState = Explicit.evalState proxy#
52−
53−-- | See 'Control.Monad.Ether.State.Strict.execStateT'.
54−execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
55−execStateT = Explicit.execStateT proxy#
56−
57−-- | See 'Control.Monad.Ether.State.Strict.execState'.
58−execState :: forall tag s a . State tag s a -> s -> s
59−execState = Explicit.execState proxy#
60−
61−-- | See 'Control.Monad.Ether.State.Strict.get'.
62−get :: forall tag s m . MonadState tag s m => m s
63−get = Explicit.get (proxy# :: Proxy# tag)
64−
65−-- | See 'Control.Monad.Ether.State.Strict.gets'.
66−gets :: forall tag s m a . MonadState tag s m => (s -> a) -> m a
67−gets = Explicit.gets (proxy# :: Proxy# tag)
68−
69−-- | See 'Control.Monad.Ether.State.Strict.put'.
70−put :: forall tag s m . MonadState tag s m => s -> m ()
71−put = Explicit.put (proxy# :: Proxy# tag)
72−
73−-- | See 'Control.Monad.Ether.State.Strict.state'.
74−state :: forall tag s m a . MonadState tag s m => (s -> (a, s)) -> m a
75−state = Explicit.state (proxy# :: Proxy# tag)
76−
77−-- | See 'Control.Monad.Ether.State.Strict.modify'.
78−modify :: forall tag s m . MonadState tag s m => (s -> s) -> m ()
79−modify = Explicit.modify (proxy# :: Proxy# tag)
src/Control/Monad/Ether/Ambiguous/Writer.hsdeleted−74
@@ -1,74 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.Writer".
6−
7−module Control.Monad.Ether.Ambiguous.Writer
8− (
9− -- * MonadWriter class
10− MonadWriter
11− , writer
12− , tell
13− , listen
14− , pass
15− , listens
16− , censor
17− -- * The Writer monad
18− , Writer
19− , runWriter
20− , execWriter
21− -- * The WriterT monad transformer
22− , WriterT
23− , writerT
24− , runWriterT
25− , execWriterT
26− ) where
27−
28−import GHC.Prim (Proxy#, proxy#)
29−import Control.Monad.Ether.Writer (MonadWriter, WriterT, Writer)
30−import qualified Control.Monad.Ether.Writer as Explicit
31−
32−-- | See 'Control.Monad.Ether.Writer.writer'.
33−writer :: forall tag w m a . MonadWriter tag w m => (a, w) -> m a
34−writer = Explicit.writer (proxy# :: Proxy# tag)
35−
36−-- | See 'Control.Monad.Ether.Writer.tell'.
37−tell :: forall tag w m . MonadWriter tag w m => w -> m ()
38−tell = Explicit.tell (proxy# :: Proxy# tag)
39−
40−-- | See 'Control.Monad.Ether.Writer.listen'.
41−listen :: forall tag w m a . MonadWriter tag w m => m a -> m (a, w)
42−listen = Explicit.listen (proxy# :: Proxy# tag)
43−
44−-- | See 'Control.Monad.Ether.Writer.pass'.
45−pass :: forall tag w m a . MonadWriter tag w m => m (a, w -> w) -> m a
46−pass = Explicit.pass (proxy# :: Proxy# tag)
47−
48−-- | See 'Control.Monad.Ether.Writer.listens'.
49−listens :: forall tag w m a b . MonadWriter tag w m => (w -> b) -> m a -> m (a, b)
50−listens = Explicit.listens (proxy# :: Proxy# tag)
51−
52−-- | See 'Control.Monad.Ether.Writer.censor'.
53−censor :: forall tag w m a . MonadWriter tag w m => (w -> w) -> m a -> m a
54−censor = Explicit.censor (proxy# :: Proxy# tag)
55−
56−-- | See 'Control.Monad.Ether.Writer.runWriter'.
57−runWriter :: forall tag w a . Writer tag w a -> (a, w)
58−runWriter = Explicit.runWriter proxy#
59−
60−-- | See 'Control.Monad.Ether.Writer.execWriter'.
61−execWriter :: forall tag w a . Writer tag w a -> w
62−execWriter = Explicit.execWriter proxy#
63−
64−-- | See 'Control.Monad.Ether.Writer.writerT'.
65−writerT :: forall tag w m a . m (a, w) -> WriterT tag w m a
66−writerT = Explicit.writerT proxy#
67−
68−-- | See 'Control.Monad.Ether.Writer.runWriterT'.
69−runWriterT :: forall tag w m a . WriterT tag w m a -> m (a, w)
70−runWriterT = Explicit.runWriterT proxy#
71−
72−-- | See 'Control.Monad.Ether.Writer.execWriterT'.
73−execWriterT :: forall tag w m a . Monad m => WriterT tag w m a -> m w
74−execWriterT = Explicit.execWriterT proxy#
src/Control/Monad/Ether/Except.hs+20−7
@@ -1,3 +1,4 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
12{-# LANGUAGE MagicHash #-}
23
34-- | See "Control.Monad.Except".
@@ -5,7 +6,9 @@
56module Control.Monad.Ether.Except
67 (
78 -- * MonadExcept class
8− MonadExcept(..)
9+ MonadExcept
10+ , throw
11+ , catch
912 -- * The Except monad
1013 , Except
1114 , runExcept
@@ -18,15 +21,25 @@ module Control.Monad.Ether.Except
1821 , handle
1922 ) where
2023
21−import GHC.Prim (Proxy#)
22−import Control.Monad.Ether.Except.Class
24+import GHC.Prim (Proxy#, proxy#)
25+import Control.Monad.Ether.Except.Class (MonadExcept)
26+import qualified Control.Monad.Ether.Except.Class as C
2327import Control.Monad.Trans.Ether.Except hiding (throw, catch)
2428import Data.Functor.Identity (Identity(..))
2529
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+
2639-- | Runs an 'Except' and handles the exception with the given function.
27−handle :: Proxy# tag -> (e -> a) -> Except tag e a -> a
28−handle t h m = runIdentity (handleT t h m)
40+handle :: forall tag e a . (e -> a) -> Except tag e a -> a
41+handle h m = runIdentity (handleT @tag h m)
2942
3043-- | Runs an 'ExceptT' and handles the exception with the given function.
31−handleT :: Functor m => Proxy# tag -> (e -> a) -> ExceptT tag e m a -> m a
32−handleT t h m = fmap (either h id) (runExceptT t m)
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)
src/Control/Monad/Ether/Except/Class.hs+4−7
@@ -1,16 +1,13 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
21{-# LANGUAGE FlexibleInstances #-}
32{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
53{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
74{-# LANGUAGE MagicHash #-}
85
96-- | See "Control.Monad.Except".
107
118module Control.Monad.Ether.Except.Class
12− ( MonadExcept(..)
13− ) where
9+ ( MonadExcept(..)
10+ ) where
1411
1512import GHC.Prim (Proxy#)
1613import qualified Control.Monad.Trans.Ether.Except as E
@@ -27,8 +24,8 @@ class Monad m => MonadExcept tag e m | m tag -> e where
2724 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
2825
2926instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
30− throw = E.throw
31− catch = E.catch
27+ throw _ = E.throw @tag
28+ catch _ = E.catch @tag
3229
3330instance {-# OVERLAPPABLE #-}
3431 ( Lift.LiftCatch t
src/Control/Monad/Ether/Implicit/Except.hs+1−3
@@ -1,6 +1,4 @@
11{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
42
53-- | See "Control.Monad.Ether.Except".
64
@@ -22,7 +20,7 @@ module Control.Monad.Ether.Implicit.Except
2220 , handleT
2321 ) where
2422
25−import qualified Control.Monad.Ether.Ambiguous.Except as A
23+import qualified Control.Monad.Ether.Except as A
2624
2725-- | See 'Control.Monad.Ether.Except.MonadExcept'.
2826type MonadExcept e = A.MonadExcept e e
src/Control/Monad/Ether/Implicit/Reader.hs+1−3
@@ -1,6 +1,4 @@
11{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
42
53-- | See "Control.Monad.Ether.Reader".
64
@@ -21,7 +19,7 @@ module Control.Monad.Ether.Implicit.Reader
2119 , runReaderT
2220 ) where
2321
24−import qualified Control.Monad.Ether.Ambiguous.Reader as A
22+import qualified Control.Monad.Ether.Reader as A
2523
2624-- | See 'Control.Monad.Ether.Reader.ReaderT'.
2725type ReaderT r = A.ReaderT r r
src/Control/Monad/Ether/Implicit/State/Lazy.hs+1−3
@@ -1,6 +1,4 @@
11{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
42
53-- | See "Control.Monad.Ether.State.Lazy".
64
@@ -26,7 +24,7 @@ module Control.Monad.Ether.Implicit.State.Lazy
2624 , execStateT
2725 ) where
2826
29−import qualified Control.Monad.Ether.Ambiguous.State.Lazy as A
27+import qualified Control.Monad.Ether.State.Lazy as A
3028
3129-- | See 'Control.Monad.Ether.State.Lazy.StateT'.
3230type StateT s = A.StateT s s
src/Control/Monad/Ether/Implicit/State/Strict.hs+1−3
@@ -1,6 +1,4 @@
11{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
42
53-- | See "Control.Monad.Ether.State.Strict".
64
@@ -26,7 +24,7 @@ module Control.Monad.Ether.Implicit.State.Strict
2624 , execStateT
2725 ) where
2826
29−import qualified Control.Monad.Ether.Ambiguous.State.Strict as A
27+import qualified Control.Monad.Ether.State.Strict as A
3028
3129-- | See 'Control.Monad.Ether.State.Strict.StateT'.
3230type StateT s = A.StateT s s
src/Control/Monad/Ether/Implicit/Writer.hs+1−3
@@ -1,6 +1,4 @@
11{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
42
53-- | See "Control.Monad.Ether.Writer".
64
@@ -25,7 +23,7 @@ module Control.Monad.Ether.Implicit.Writer
2523 , execWriterT
2624 ) where
2725
28−import qualified Control.Monad.Ether.Ambiguous.Writer as A
26+import qualified Control.Monad.Ether.Writer as A
2927
3028-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
3129type MonadWriter w = A.MonadWriter w w
src/Control/Monad/Ether/Reader.hs+42−2
@@ -1,10 +1,15 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
13
24-- | See "Control.Monad.Reader".
35
46module Control.Monad.Ether.Reader
57 (
68 -- * MonadReader class
7− MonadReader(..)
9+ MonadReader
10+ , ask
11+ , local
12+ , reader
813 , asks
914 -- * The Reader monad
1015 , Reader
@@ -15,5 +20,40 @@ module Control.Monad.Ether.Reader
1520 , runReaderT
1621 ) where
1722
18−import Control.Monad.Ether.Reader.Class
23+import GHC.Prim (Proxy#, proxy#)
24+import Control.Monad.Ether.Reader.Class (MonadReader)
25+import qualified Control.Monad.Ether.Reader.Class as C
1926import 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)
src/Control/Monad/Ether/Reader/Class.hs+5−18
@@ -1,17 +1,13 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
21{-# LANGUAGE FlexibleInstances #-}
32{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
53{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
74{-# LANGUAGE MagicHash #-}
85
96-- | See "Control.Monad.Reader.Class".
107
118module Control.Monad.Ether.Reader.Class
12− ( MonadReader(..)
13− , asks
14− ) where
9+ ( MonadReader(..)
10+ ) where
1511
1612import GHC.Prim (Proxy#)
1713import qualified Control.Monad.Trans.Ether.Reader as R
@@ -43,19 +39,10 @@ class Monad m => MonadReader tag r m | m tag -> r where
4339 -> m a
4440 reader t f = fmap f (ask t)
4541
46−-- | Retrieves a function of the current environment.
47−asks
48− :: MonadReader tag r m
49− => Proxy# tag
50− -> (r -> a)
51− -- ^ The selector function to apply to the environment.
52− -> m a
53−asks = reader
54−
5542instance (Monad m, r ~ r') => MonadReader tag r (R.ReaderT tag r' m) where
56− ask = R.ask
57− local = R.local
58− reader = R.reader
43+ ask _ = R.ask @tag
44+ local _ = R.local @tag
45+ reader _ = R.reader @tag
5946
6047instance {-# OVERLAPPABLE #-}
6148 ( Lift.LiftLocal t
src/Control/Monad/Ether/State/Class.hs+8−21
@@ -1,18 +1,13 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
21{-# LANGUAGE FlexibleInstances #-}
32{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
53{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
74{-# LANGUAGE MagicHash #-}
85
96-- | See "Control.Monad.State.Class".
107
118module Control.Monad.Ether.State.Class
12− ( MonadState(..)
13− , modify
14− , gets
15− ) where
9+ ( MonadState(..)
10+ ) where
1611
1712import GHC.Prim (Proxy#)
1813import qualified Control.Monad.Trans.Ether.State.Lazy as S.L
@@ -40,23 +35,15 @@ class Monad m => MonadState tag s m | m tag -> s where
4035 put t s'
4136 return a
4237
43−-- | Modifies the state inside a state monad.
44−modify :: MonadState tag s m => Proxy# tag -> (s -> s) -> m ()
45−modify t f = state t (\s -> ((), f s))
46−
47−-- | Gets specific component of the state, using a projection function supplied.
48−gets :: MonadState tag s m => Proxy# tag -> (s -> a) -> m a
49−gets t f = fmap f (get t)
50−
5138instance (Monad m, s ~ s') => MonadState tag s (S.L.StateT tag s' m) where
52− get = S.L.get
53− put = S.L.put
54− state = S.L.state
39+ get _ = S.L.get @tag
40+ put _ = S.L.put @tag
41+ state _ = S.L.state @tag
5542
5643instance (Monad m, s ~ s') => MonadState tag s (S.S.StateT tag s' m) where
57− get = S.S.get
58− put = S.S.put
59− state = S.S.state
44+ get _ = S.S.get @tag
45+ put _ = S.S.put @tag
46+ state _ = S.S.state @tag
6047
6148instance {-# OVERLAPPABLE #-}
6249 ( Lift.MonadTrans t
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)
src/Control/Monad/Ether/State/Lazy.hs+5−2
@@ -4,7 +4,10 @@
44module Control.Monad.Ether.State.Lazy
55 (
66 -- * MonadState class
7− MonadState(..)
7+ MonadState
8+ , get
9+ , put
10+ , state
811 , modify
912 , gets
1013 -- * The State monad
@@ -20,5 +23,5 @@ module Control.Monad.Ether.State.Lazy
2023 , execStateT
2124 ) where
2225
23−import Control.Monad.Ether.State.Class
26+import Control.Monad.Ether.State.Common
2427import Control.Monad.Trans.Ether.State.Lazy hiding (state, get, put)
src/Control/Monad/Ether/State/Strict.hs+5−2
@@ -4,7 +4,10 @@
44module Control.Monad.Ether.State.Strict
55 (
66 -- * MonadState class
7− MonadState(..)
7+ MonadState
8+ , get
9+ , put
10+ , state
811 , modify
912 , gets
1013 -- * The State monad
@@ -20,5 +23,5 @@ module Control.Monad.Ether.State.Strict
2023 , execStateT
2124 ) where
2225
23−import Control.Monad.Ether.State.Class
26+import Control.Monad.Ether.State.Common
2427import Control.Monad.Trans.Ether.State.Strict hiding (state, get, put)
src/Control/Monad/Ether/Writer.hs+41−2
@@ -1,10 +1,16 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
13
24-- | See "Control.Monad.Writer".
35
46module Control.Monad.Ether.Writer
57 (
68 -- * MonadWriter class
7− MonadWriter(..)
9+ MonadWriter
10+ , writer
11+ , tell
12+ , listen
13+ , pass
814 , listens
915 , censor
1016 -- * The Writer monad
@@ -18,5 +24,38 @@ module Control.Monad.Ether.Writer
1824 , execWriterT
1925 ) where
2026
21−import Control.Monad.Ether.Writer.Class
27+import GHC.Prim (Proxy#, proxy#)
28+import Control.Monad.Ether.Writer.Class (MonadWriter)
29+import qualified Control.Monad.Ether.Writer.Class as C
2230import 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)
src/Control/Monad/Ether/Writer/Class.hs+6−24
@@ -1,18 +1,13 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
21{-# LANGUAGE FlexibleInstances #-}
32{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
53{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
74{-# LANGUAGE MagicHash #-}
85
96-- | See "Control.Monad.Writer.Class".
107
118module Control.Monad.Ether.Writer.Class
12− ( MonadWriter(..)
13− , listens
14− , censor
15− ) where
9+ ( MonadWriter(..)
10+ ) where
1611
1712import GHC.Prim (Proxy#)
1813import qualified Control.Monad.Trans.Ether.Writer as W
@@ -42,24 +37,11 @@ class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where
4237 -- and return the value, applying the function to the accumulator.
4338 pass :: Proxy# tag -> m (a, w -> w) -> m a
4439
45−-- | Execute an action and add the result of applying the given function to
46−-- its accumulator to the value of the computation.
47−listens :: MonadWriter tag w m => Proxy# tag -> (w -> b) -> m a -> m (a, b)
48−listens t f m = do
49− ~(a, w) <- listen t m
50− return (a, f w)
51−
52−-- | Execute an action and apply a function to its accumulator.
53−censor :: MonadWriter tag w m => Proxy# tag -> (w -> w) -> m a -> m a
54−censor t f m = pass t $ do
55− a <- m
56− return (a, f)
57−
5840instance (Monoid w, Monad m, w ~ w') => MonadWriter tag w (W.WriterT tag w' m) where
59− writer = W.writer
60− tell = W.tell
61− listen = W.listen
62− pass = W.pass
41+ writer _ = W.writer @tag
42+ tell _ = W.tell @tag
43+ listen _ = W.listen @tag
44+ pass _ = W.pass @tag
6345
6446instance {-# OVERLAPPABLE #-}
6547 ( Lift.LiftListen t
src/Control/Monad/Trans/Ether/Dispatch.hs+25−25
@@ -1,15 +1,11 @@
11{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
22
33{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE MultiParamTypeClasses #-}
54{-# LANGUAGE TypeFamilies #-}
65{-# LANGUAGE FlexibleInstances #-}
76{-# LANGUAGE UndecidableInstances #-}
8−{-# LANGUAGE ScopedTypeVariables #-}
97{-# LANGUAGE DataKinds #-}
10−{-# LANGUAGE PolyKinds #-}
118{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12−{-# LANGUAGE MagicHash #-}
139
1410{- |
1511
@@ -63,7 +59,6 @@ import Control.Monad.Morph (MFunctor, MMonad)
6359import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
6460import GHC.Generics (Generic)
6561import Data.Coerce (coerce)
66−import GHC.Prim (Proxy#, proxy#)
6762
6863import qualified Control.Monad.Base as MB
6964import qualified Control.Monad.Trans.Control as MC
@@ -81,6 +76,11 @@ import Control.Monad.Ether.State.Class
8176import Control.Monad.Ether.Except.Class
8277import Control.Monad.Ether.Writer.Class
8378
79+import Control.Monad.Ether.Reader as A
80+import Control.Monad.Ether.State.Common as A
81+import Control.Monad.Ether.Except as A
82+import Control.Monad.Ether.Writer as A
83+
8484import qualified Control.Monad.Reader as Class
8585import qualified Control.Monad.State as Class
8686import qualified Control.Monad.Except as Class
@@ -156,47 +156,47 @@ tagReplace = coerce
156156
157157instance MonadReader tag r m
158158 => Class.MonadReader r (DispatchTagAttachT tag m) where
159− ask = let t = proxy# :: Proxy# tag in Lift.lift (ask t)
160− local = let t = proxy# :: Proxy# tag in Lift.liftLocal (ask t) (local t)
159+ ask = Lift.lift (A.ask @tag)
160+ local = Lift.liftLocal (A.ask @tag) (A.local @tag)
161161
162162instance MonadState tag s m
163163 => Class.MonadState s (DispatchTagAttachT tag m) where
164− get = let t = proxy# :: Proxy# tag in Lift.lift (get t)
165− put = let t = proxy# :: Proxy# tag in Lift.lift . put t
164+ get = Lift.lift (A.get @tag)
165+ put = Lift.lift . A.put @tag
166166
167167instance MonadExcept tag e m
168168 => Class.MonadError e (DispatchTagAttachT tag m) where
169− throwError = let t = proxy# :: Proxy# tag in Lift.lift . throw t
170− catchError = let t = proxy# :: Proxy# tag in Lift.liftCatch (catch t)
169+ throwError = Lift.lift . A.throw @tag
170+ catchError = Lift.liftCatch (A.catch @tag)
171171
172172instance MonadWriter tag w m
173173 => Class.MonadWriter w (DispatchTagAttachT tag m) where
174− writer = let t = proxy# :: Proxy# tag in Lift.lift . writer t
175− tell = let t = proxy# :: Proxy# tag in Lift.lift . tell t
176− listen = let t = proxy# :: Proxy# tag in Lift.liftListen (listen t)
177− pass = let t = proxy# :: Proxy# tag in Lift.liftPass (pass t)
174+ writer = Lift.lift . A.writer @tag
175+ tell = Lift.lift . A.tell @tag
176+ listen = Lift.liftListen (A.listen @tag)
177+ pass = Lift.liftPass (A.pass @tag)
178178
179179
180180-- TagReplace instances
181181
182182instance MonadReader tNew r m
183183 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
184− ask _ = let t = proxy# :: Proxy# tNew in Lift.lift (ask t)
185− local _ = let t = proxy# :: Proxy# tNew in Lift.liftLocal (ask t) (local t)
184+ ask _ = Lift.lift (A.ask @tNew)
185+ local _ = Lift.liftLocal (A.ask @tNew) (A.local @tNew)
186186
187187instance MonadState tNew s m
188188 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
189− get _ = let t = proxy# :: Proxy# tNew in Lift.lift (get t)
190− put _ = let t = proxy# :: Proxy# tNew in Lift.lift . put t
189+ get _ = Lift.lift (A.get @tNew)
190+ put _ = Lift.lift . A.put @tNew
191191
192192instance MonadExcept tNew e m
193193 => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
194− throw _ = let t = proxy# :: Proxy# tNew in Lift.lift . throw t
195− catch _ = let t = proxy# :: Proxy# tNew in Lift.liftCatch (catch t)
194+ throw _ = Lift.lift . A.throw @tNew
195+ catch _ = Lift.liftCatch (A.catch @tNew)
196196
197197instance MonadWriter tNew w m
198198 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
199− writer _ = let t = proxy# :: Proxy# tNew in Lift.lift . writer t
200− tell _ = let t = proxy# :: Proxy# tNew in Lift.lift . tell t
201− listen _ = let t = proxy# :: Proxy# tNew in Lift.liftListen (listen t)
202− pass _ = let t = proxy# :: Proxy# tNew in Lift.liftPass (pass t)
199+ writer _ = Lift.lift . A.writer @tNew
200+ tell _ = Lift.lift . A.tell @tNew
201+ listen _ = Lift.liftListen (A.listen @tNew)
202+ pass _ = Lift.liftPass (A.pass @tNew)
src/Control/Monad/Trans/Ether/Except.hs+15−16
@@ -1,12 +1,10 @@
11{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
32{-# LANGUAGE TypeFamilies #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE UndecidableInstances #-}
65{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
86{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
108
119-- | See "Control.Monad.Trans.Except".
1210
@@ -25,7 +23,6 @@ module Control.Monad.Trans.Ether.Except
2523 , catch
2624 ) where
2725
28−import GHC.Prim (Proxy#)
2926import Data.Functor.Identity (Identity(..))
3027import qualified Control.Monad.Trans.Except as Trans
3128import Control.Monad.Trans.Ether.Tagged
@@ -40,8 +37,8 @@ import Control.Monad.Trans.Ether.Tagged
4037type Except tag e = ExceptT tag e Identity
4138
4239-- | Runs an 'Except' and returns either an exception or a normal value.
43−runExcept :: Proxy# tag -> Except tag e a -> Either e a
44−runExcept _ = Trans.runExcept . unpack
40+runExcept :: forall tag e a . Except tag e a -> Either e a
41+runExcept = Trans.runExcept . unpack
4542
4643-- | The exception monad transformer.
4744--
@@ -50,22 +47,24 @@ runExcept _ = Trans.runExcept . unpack
5047type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
5148
5249-- | Constructor for computations in the exception monad transformer.
53−exceptT :: Proxy# tag -> m (Either e a) -> ExceptT tag e m a
54−exceptT _ = pack . Trans.ExceptT
50+exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
51+exceptT = pack . Trans.ExceptT
5552
5653-- | Constructor for computations in the exception monad
5754-- (the inverse of 'runExcept').
58−except :: Monad m => Proxy# tag -> Either e a -> ExceptT tag e m a
59−except t = exceptT t . return
55+except :: forall tag e m a . Monad m => Either e a -> ExceptT tag e m a
56+except = exceptT @tag . return
6057
6158-- | Runs an 'ExceptT' and returns either an exception or a normal value.
62−runExceptT :: Proxy# tag -> ExceptT tag e m a -> m (Either e a)
63−runExceptT _ = Trans.runExceptT . unpack
59+runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
60+runExceptT = Trans.runExceptT . unpack
6461
6562-- | Is used within a monadic computation to begin exception processing.
66−throw :: Monad m => Proxy# tag -> e -> ExceptT tag e m a
67−throw _ = pack . Trans.throwE
63+throw :: forall tag e m a . Monad m => e -> ExceptT tag e m a
64+throw = pack . Trans.throwE
6865
6966-- | A handler function to handle previous exceptions and return to normal execution.
70−catch :: Monad m => Proxy# tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
71−catch _ m h = pack $ Trans.catchE (unpack m) (unpack . h)
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)
src/Control/Monad/Trans/Ether/Reader.hs+14−17
@@ -1,12 +1,10 @@
11{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
32{-# LANGUAGE TypeFamilies #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE UndecidableInstances #-}
65{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
86{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
108
119-- | See "Control.Monad.Trans.Reader".
1210
@@ -25,7 +23,6 @@ module Control.Monad.Trans.Ether.Reader
2523 , local
2624 ) where
2725
28−import GHC.Prim (Proxy#)
2926import Data.Functor.Identity (Identity(..))
3027import qualified Control.Monad.Trans.Reader as Trans
3128import Control.Monad.Trans.Ether.Tagged
@@ -46,37 +43,37 @@ type Reader tag r = ReaderT tag r Identity
4643type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
4744
4845-- | Constructor for computations in the reader monad transformer.
49−readerT :: Proxy# tag -> (r -> m a) -> ReaderT tag r m a
50−readerT _ = pack . Trans.ReaderT
46+readerT :: forall tag r m a . (r -> m a) -> ReaderT tag r m a
47+readerT = pack . Trans.ReaderT
5148
5249-- | Constructor for computations in the reader monad
5350-- (the inverse of 'runReader').
54−reader :: Monad m => Proxy# tag -> (r -> a) -> ReaderT tag r m a
55−reader _ = pack . Trans.reader
51+reader :: forall tag r m a . Monad m => (r -> a) -> ReaderT tag r m a
52+reader = pack . Trans.reader
5653
5754-- | Runs a 'ReaderT' with the given environment
5855-- and returns the final value.
59−runReaderT :: Proxy# tag -> ReaderT tag r m a -> r -> m a
60−runReaderT _ = Trans.runReaderT . unpack
56+runReaderT :: forall tag r m a . ReaderT tag r m a -> r -> m a
57+runReaderT = Trans.runReaderT . unpack
6158
6259-- | Runs a 'ReaderT' with the given environment
6360-- and returns the final value.
64−runReader :: Proxy# tag -> Reader tag r a -> r -> a
65−runReader _ = Trans.runReader . unpack
61+runReader :: forall tag r a . Reader tag r a -> r -> a
62+runReader = Trans.runReader . unpack
6663
6764-- | Fetch the value of the environment.
68−ask :: Monad m => Proxy# tag -> ReaderT tag r m r
69−ask _ = pack Trans.ask
65+ask :: forall tag r m . Monad m => ReaderT tag r m r
66+ask = pack Trans.ask
7067
7168-- | Execute a computation in a modified environment
7269-- (a specialization of 'withReaderT').
7370--
7471-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
7572local
76− :: Proxy# tag
77− -> (r -> r)
73+ :: forall tag r m a
74+ . (r -> r)
7875 -- ^ The function to modify the environment.
7976 -> ReaderT tag r m a
8077 -- ^ Computation to run in the modified environment.
8178 -> ReaderT tag r m a
82−local _ f = pack . Trans.withReaderT f . unpack
79+local f = pack . Trans.withReaderT f . unpack
src/Control/Monad/Trans/Ether/State/Lazy.hs+21−24
@@ -1,12 +1,10 @@
11{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
32{-# LANGUAGE TypeFamilies #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE UndecidableInstances #-}
65{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
86{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
108
119-- | See "Control.Monad.Trans.State.Lazy".
1210
@@ -29,7 +27,6 @@ module Control.Monad.Trans.Ether.State.Lazy
2927 , put
3028 ) where
3129
32−import GHC.Prim (Proxy#)
3330import Data.Functor.Identity (Identity(..))
3431import qualified Control.Monad.Trans.State.Lazy as Trans
3532import Control.Monad.Trans.Ether.Tagged
@@ -49,48 +46,48 @@ type State tag r = StateT tag r Identity
4946type StateT tag s = TaggedTrans tag (Trans.StateT s)
5047
5148-- | Constructor for computations in the state monad transformer.
52−stateT :: Proxy# tag -> (s -> m (a, s)) -> StateT tag s m a
53−stateT _ = pack . Trans.StateT
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
50+stateT = pack . Trans.StateT
5451
5552-- | Constructor for computations in the state monad
5653-- (the inverse of 'runState').
57−state :: Monad m => Proxy# tag -> (s -> (a, s)) -> StateT tag s m a
58−state _ = pack . Trans.state
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
55+state = pack . Trans.state
5956
6057-- | Runs a 'StateT' with the given initial state
6158-- and returns both the final value and the final state.
62−runStateT :: Proxy# tag -> StateT tag s m a -> s -> m (a, s)
63−runStateT _ = Trans.runStateT . unpack
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
60+runStateT = Trans.runStateT . unpack
6461
6562-- | Runs a 'StateT' with the given initial state
6663-- and returns the final value, discarding the final state.
67−evalStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m a
68−evalStateT _ = Trans.evalStateT . unpack
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
65+evalStateT = Trans.evalStateT . unpack
6966
7067-- | Runs a 'StateT' with the given initial state
7168-- and returns the final state, discarding the final value.
72−execStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m s
73−execStateT _ = Trans.execStateT . unpack
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
70+execStateT = Trans.execStateT . unpack
7471
7572-- | Runs a 'State' with the given initial state
7673-- and returns both the final value and the final state.
77−runState :: Proxy# tag -> State tag s a -> s -> (a, s)
78−runState _ = Trans.runState . unpack
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
75+runState = Trans.runState . unpack
7976
8077-- | Runs a 'State' with the given initial state
8178-- and returns the final value, discarding the final state.
82−evalState :: Proxy# tag -> State tag s a -> s -> a
83−evalState _ = Trans.evalState . unpack
79+evalState :: forall tag s a . State tag s a -> s -> a
80+evalState = Trans.evalState . unpack
8481
8582-- | Runs a 'State' with the given initial state
8683-- and returns the final state, discarding the final value.
87−execState :: Proxy# tag -> State tag s a -> s -> s
88−execState _ = Trans.execState . unpack
84+execState :: forall tag s a . State tag s a -> s -> s
85+execState = Trans.execState . unpack
8986
9087-- | Fetch the current value of the state within the monad.
91−get :: Monad m => Proxy# tag -> StateT tag s m s
92−get _ = pack Trans.get
88+get :: forall tag s m . Monad m => StateT tag s m s
89+get = pack Trans.get
9390
9491-- | Set the value of the state within the monad.
95−put :: Monad m => Proxy# tag -> s -> StateT tag s m ()
96−put _ = pack . Trans.put
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
93+put = pack . Trans.put
src/Control/Monad/Trans/Ether/State/Strict.hs+21−24
@@ -1,12 +1,10 @@
11{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
32{-# LANGUAGE TypeFamilies #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE UndecidableInstances #-}
65{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
86{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
108
119-- | See "Control.Monad.Trans.State.Strict".
1210
@@ -29,7 +27,6 @@ module Control.Monad.Trans.Ether.State.Strict
2927 , put
3028 ) where
3129
32−import GHC.Prim (Proxy#)
3330import Data.Functor.Identity (Identity(..))
3431import qualified Control.Monad.Trans.State.Strict as Trans
3532import Control.Monad.Trans.Ether.Tagged
@@ -49,48 +46,48 @@ type State tag r = StateT tag r Identity
4946type StateT tag s = TaggedTrans tag (Trans.StateT s)
5047
5148-- | Constructor for computations in the state monad transformer.
52−stateT :: Proxy# tag -> (s -> m (a, s)) -> StateT tag s m a
53−stateT _ = pack . Trans.StateT
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
50+stateT = pack . Trans.StateT
5451
5552-- | Constructor for computations in the state monad
5653-- (the inverse of 'runState').
57−state :: Monad m => Proxy# tag -> (s -> (a, s)) -> StateT tag s m a
58−state _ = pack . Trans.state
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
55+state = pack . Trans.state
5956
6057-- | Runs a 'StateT' with the given initial state
6158-- and returns both the final value and the final state.
62−runStateT :: Proxy# tag -> StateT tag s m a -> s -> m (a, s)
63−runStateT _ = Trans.runStateT . unpack
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
60+runStateT = Trans.runStateT . unpack
6461
6562-- | Runs a 'StateT' with the given initial state
6663-- and returns the final value, discarding the final state.
67−evalStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m a
68−evalStateT _ = Trans.evalStateT . unpack
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
65+evalStateT = Trans.evalStateT . unpack
6966
7067-- | Runs a 'StateT' with the given initial state
7168-- and returns the final state, discarding the final value.
72−execStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m s
73−execStateT _ = Trans.execStateT . unpack
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
70+execStateT = Trans.execStateT . unpack
7471
7572-- | Runs a 'State' with the given initial state
7673-- and returns both the final value and the final state.
77−runState :: Proxy# tag -> State tag s a -> s -> (a, s)
78−runState _ = Trans.runState . unpack
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
75+runState = Trans.runState . unpack
7976
8077-- | Runs a 'State' with the given initial state
8178-- and returns the final value, discarding the final state.
82−evalState :: Proxy# tag -> State tag s a -> s -> a
83−evalState _ = Trans.evalState . unpack
79+evalState :: forall tag s a . State tag s a -> s -> a
80+evalState = Trans.evalState . unpack
8481
8582-- | Runs a 'State' with the given initial state
8683-- and returns the final state, discarding the final value.
87−execState :: Proxy# tag -> State tag s a -> s -> s
88−execState _ = Trans.execState . unpack
84+execState :: forall tag s a . State tag s a -> s -> s
85+execState = Trans.execState . unpack
8986
9087-- | Fetch the current value of the state within the monad.
91−get :: Monad m => Proxy# tag -> StateT tag s m s
92−get _ = pack Trans.get
88+get :: forall tag s m . Monad m => StateT tag s m s
89+get = pack Trans.get
9390
9491-- | Set the value of the state within the monad.
95−put :: Monad m => Proxy# tag -> s -> StateT tag s m ()
96−put _ = pack . Trans.put
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
93+put = pack . Trans.put
src/Control/Monad/Trans/Ether/Tagged.hs−2
@@ -1,8 +1,6 @@
11{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE GeneralizedNewtypeDeriving #-}
33{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE PolyKinds #-}
5−{-# LANGUAGE MultiParamTypeClasses #-}
64{-# LANGUAGE UndecidableInstances #-}
75{-# LANGUAGE ConstraintKinds #-}
86{-# LANGUAGE TypeFamilies #-}
src/Control/Monad/Trans/Ether/Writer.hs+19−22
@@ -1,12 +1,10 @@
11{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
32{-# LANGUAGE TypeFamilies #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE UndecidableInstances #-}
65{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
86{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
108
119-- | See "Control.Monad.Trans.Writer".
1210
@@ -28,7 +26,6 @@ module Control.Monad.Trans.Ether.Writer
2826 , pass
2927 ) where
3028
31−import GHC.Prim (Proxy#)
3229import Data.Functor.Identity (Identity(..))
3330import qualified Control.Monad.Trans.Writer.Lazy as Trans
3431import Control.Monad.Trans.Ether.Tagged
@@ -48,43 +45,43 @@ type Writer tag w = WriterT tag w Identity
4845type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
4946
5047-- | Constructor for computations in the writer monad transformer.
51−writerT :: Proxy# tag -> m (a, w) -> WriterT tag w m a
52−writerT _ = pack . Trans.WriterT
48+writerT :: forall tag w m a . m (a, w) -> WriterT tag w m a
49+writerT = pack . Trans.WriterT
5350
5451-- | Constructor for computations in the writer monad
5552-- (the inverse of 'runWriter').
56−writer :: Monad m => Proxy# tag -> (a, w) -> WriterT tag w m a
57−writer _ = pack . Trans.writer
53+writer :: forall tag w m a . Monad m => (a, w) -> WriterT tag w m a
54+writer = pack . Trans.writer
5855
5956-- | Runs a 'WriterT' and returns both the normal value
6057-- and the final accumulator.
61−runWriterT :: Proxy# tag -> WriterT tag w m a -> m (a, w)
62−runWriterT _ = Trans.runWriterT . unpack
58+runWriterT :: forall tag w m a . WriterT tag w m a -> m (a, w)
59+runWriterT = Trans.runWriterT . unpack
6360
6461-- | Runs a 'Writer' and returns both the normal value
6562-- and the final accumulator.
66−runWriter :: Proxy# tag -> Writer tag w a -> (a, w)
67−runWriter _ = Trans.runWriter . unpack
63+runWriter :: forall tag w a . Writer tag w a -> (a, w)
64+runWriter = Trans.runWriter . unpack
6865
6966-- | Runs a 'WriterT' and returns the final accumulator,
7067-- discarding the normal value.
71−execWriterT :: Monad m => Proxy# tag -> WriterT tag w m a -> m w
72−execWriterT _ = Trans.execWriterT . unpack
68+execWriterT :: forall tag w m a . Monad m => WriterT tag w m a -> m w
69+execWriterT = Trans.execWriterT . unpack
7370
7471-- | Runs a 'Writer' and returns the final accumulator,
7572-- discarding the normal value.
76−execWriter :: Proxy# tag -> Writer tag w a -> w
77−execWriter _ = Trans.execWriter . unpack
73+execWriter :: forall tag w a . Writer tag w a -> w
74+execWriter = Trans.execWriter . unpack
7875
7976-- | Appends a value to the accumulator within the monad.
80−tell :: Monad m => Proxy# tag -> w -> WriterT tag w m ()
81−tell t w = writer t ((), w)
77+tell :: forall tag w m . Monad m => w -> WriterT tag w m ()
78+tell w = writer @tag ((), w)
8279
8380-- | Executes an action and adds its accumulator to the value of the computation.
84−listen :: Monad m => Proxy# tag -> WriterT tag w m a -> WriterT tag w m (a, w)
85−listen _ = pack . Trans.listen . unpack
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
8683
8784-- | Executes an action which returns a value and a function, and returns the
8885-- value, applying the function to the accumulator.
89−pass :: Monad m => Proxy# tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
90−pass _ = pack . Trans.pass . unpack
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
test/Regression/T1.hs+1−1
@@ -1,6 +1,6 @@
11module Regression.T1 (test1) where
22
3−import Control.Monad.Ether.Ambiguous
3+import Control.Monad.Ether
44import Control.Ether.Abbr
55
66import Test.Tasty
test/Regression/T3.hs+1−1
@@ -1,7 +1,7 @@
11module Regression.T3 (test3) where
22
33import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
55
66import qualified Control.Monad.Reader as T
77import qualified Control.Monad.State as T
test/Regression/T4.hs+1−1
@@ -1,7 +1,7 @@
11module Regression.T4 (test4) where
22
33import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
55
66import Test.Tasty
77import Test.Tasty.QuickCheck
test/Regression/T7.hs+1−1
@@ -3,7 +3,7 @@ module Regression.T7 (test7) where
33import Data.Monoid
44import Control.Monad
55
6−import Control.Monad.Ether.Ambiguous
6+import Control.Monad.Ether
77import qualified Control.Monad.Writer as T
88
99import Test.Tasty
test/Regression/T8.hs+1−1
@@ -1,7 +1,7 @@
11module Regression.T8 (test8) where
22
33import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
55
66import qualified Control.Monad.State as T
77
test/Regression/T9.hs+1−1
@@ -1,7 +1,7 @@
11module Regression.T9 (test9) where
22
33import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
55
66import Test.Tasty
77import Test.Tasty.QuickCheck