on master help sign in
Merge pull request #22 from int-index/amb-default
0140749Index Int
ether.cabal+6−11
@@ -54,13 +54,8 @@ library
54 Control.Monad.Ether.Implicit.State.Lazy
54 Control.Monad.Ether.Implicit.State.Lazy
55 Control.Monad.Ether.Implicit.State.Strict
55 Control.Monad.Ether.Implicit.State.Strict
56 Control.Monad.Ether.Implicit.Except
56 Control.Monad.Ether.Implicit.Except
57− Control.Monad.Ether.Ambiguous
57+
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
58+ other-modules: Control.Monad.Ether.State.Common
62− Control.Monad.Ether.Ambiguous.State.Strict
63− Control.Monad.Ether.Ambiguous.Except
64
59
65 build-depends: base >=4.7 && <4.10
60 build-depends: base >=4.7 && <4.10
66 , transformers >=0.4.2
61 , transformers >=0.4.2
@@ -74,17 +69,17 @@ library
74 , ghc-prim >=0.3
69 , ghc-prim >=0.3
75
70
76 default-language: Haskell2010
71 default-language: Haskell2010
72+ default-extensions: PolyKinds
73+ ScopedTypeVariables
74+ FunctionalDependencies
75+ TypeApplications
77 other-extensions: ConstraintKinds
76 other-extensions: ConstraintKinds
78 DataKinds
77 DataKinds
79 DefaultSignatures
78 DefaultSignatures
80 DeriveGeneric
79 DeriveGeneric
81 FlexibleInstances
80 FlexibleInstances
82− FunctionalDependencies
83 GeneralizedNewtypeDeriving
81 GeneralizedNewtypeDeriving
84 MagicHash
82 MagicHash
85− MultiParamTypeClasses
86− ScopedTypeVariables
87− TypeApplications
88 TypeFamilies
83 TypeFamilies
89 TypeOperators
84 TypeOperators
90 UndecidableInstances
85 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 #-}
1{-# LANGUAGE MagicHash #-}
2{-# LANGUAGE MagicHash #-}
2
3
3-- | See "Control.Monad.Except".
4-- | See "Control.Monad.Except".
@@ -5,7 +6,9 @@
5module Control.Monad.Ether.Except
6module Control.Monad.Ether.Except
6 (
7 (
7 -- * MonadExcept class
8 -- * MonadExcept class
8− MonadExcept(..)
9+ MonadExcept
10+ , throw
11+ , catch
9 -- * The Except monad
12 -- * The Except monad
10 , Except
13 , Except
11 , runExcept
14 , runExcept
@@ -18,15 +21,25 @@ module Control.Monad.Ether.Except
18 , handle
21 , handle
19 ) where
22 ) where
20
23
21−import GHC.Prim (Proxy#)
24+import GHC.Prim (Proxy#, proxy#)
25+import Control.Monad.Ether.Except.Class (MonadExcept)
22−import Control.Monad.Ether.Except.Class
26+import qualified Control.Monad.Ether.Except.Class as C
23import Control.Monad.Trans.Ether.Except hiding (throw, catch)
27import Control.Monad.Trans.Ether.Except hiding (throw, catch)
24import Data.Functor.Identity (Identity(..))
28import Data.Functor.Identity (Identity(..))
25
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+
26-- | Runs an 'Except' and handles the exception with the given function.
39-- | Runs an 'Except' and handles the exception with the given function.
27−handle :: Proxy# tag -> (e -> a) -> Except tag e a -> a
40+handle :: forall tag e a . (e -> a) -> Except tag e a -> a
28−handle t h m = runIdentity (handleT t h m)
41+handle h m = runIdentity (handleT @tag h m)
29
42
30-- | Runs an 'ExceptT' and handles the exception with the given function.
43-- | 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
44+handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
32−handleT t h m = fmap (either h id) (runExceptT t m)
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 #-}
2{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE MagicHash #-}
4{-# LANGUAGE MagicHash #-}
8
5
9-- | See "Control.Monad.Except".
6-- | See "Control.Monad.Except".
10
7
11module Control.Monad.Ether.Except.Class
8module Control.Monad.Ether.Except.Class
12− ( MonadExcept(..)
9+ ( MonadExcept(..)
13− ) where
10+ ) where
14
11
15import GHC.Prim (Proxy#)
12import GHC.Prim (Proxy#)
16import qualified Control.Monad.Trans.Ether.Except as E
13import qualified Control.Monad.Trans.Ether.Except as E
@@ -27,8 +24,8 @@ class Monad m => MonadExcept tag e m | m tag -> e where
27 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
24 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
28
25
29instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
26instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
30− throw = E.throw
27+ throw _ = E.throw @tag
31− catch = E.catch
28+ catch _ = E.catch @tag
32
29
33instance {-# OVERLAPPABLE #-}
30instance {-# OVERLAPPABLE #-}
34 ( Lift.LiftCatch t
31 ( Lift.LiftCatch t
src/Control/Monad/Ether/Implicit/Except.hs+1−3
@@ -1,6 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4
2
5-- | See "Control.Monad.Ether.Except".
3-- | See "Control.Monad.Ether.Except".
6
4
@@ -22,7 +20,7 @@ module Control.Monad.Ether.Implicit.Except
22 , handleT
20 , handleT
23 ) where
21 ) where
24
22
25−import qualified Control.Monad.Ether.Ambiguous.Except as A
23+import qualified Control.Monad.Ether.Except as A
26
24
27-- | See 'Control.Monad.Ether.Except.MonadExcept'.
25-- | See 'Control.Monad.Ether.Except.MonadExcept'.
28type MonadExcept e = A.MonadExcept e e
26type MonadExcept e = A.MonadExcept e e
src/Control/Monad/Ether/Implicit/Reader.hs+1−3
@@ -1,6 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4
2
5-- | See "Control.Monad.Ether.Reader".
3-- | See "Control.Monad.Ether.Reader".
6
4
@@ -21,7 +19,7 @@ module Control.Monad.Ether.Implicit.Reader
21 , runReaderT
19 , runReaderT
22 ) where
20 ) where
23
21
24−import qualified Control.Monad.Ether.Ambiguous.Reader as A
22+import qualified Control.Monad.Ether.Reader as A
25
23
26-- | See 'Control.Monad.Ether.Reader.ReaderT'.
24-- | See 'Control.Monad.Ether.Reader.ReaderT'.
27type ReaderT r = A.ReaderT r r
25type ReaderT r = A.ReaderT r r
src/Control/Monad/Ether/Implicit/State/Lazy.hs+1−3
@@ -1,6 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4
2
5-- | See "Control.Monad.Ether.State.Lazy".
3-- | See "Control.Monad.Ether.State.Lazy".
6
4
@@ -26,7 +24,7 @@ module Control.Monad.Ether.Implicit.State.Lazy
26 , execStateT
24 , execStateT
27 ) where
25 ) where
28
26
29−import qualified Control.Monad.Ether.Ambiguous.State.Lazy as A
27+import qualified Control.Monad.Ether.State.Lazy as A
30
28
31-- | See 'Control.Monad.Ether.State.Lazy.StateT'.
29-- | See 'Control.Monad.Ether.State.Lazy.StateT'.
32type StateT s = A.StateT s s
30type StateT s = A.StateT s s
src/Control/Monad/Ether/Implicit/State/Strict.hs+1−3
@@ -1,6 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4
2
5-- | See "Control.Monad.Ether.State.Strict".
3-- | See "Control.Monad.Ether.State.Strict".
6
4
@@ -26,7 +24,7 @@ module Control.Monad.Ether.Implicit.State.Strict
26 , execStateT
24 , execStateT
27 ) where
25 ) where
28
26
29−import qualified Control.Monad.Ether.Ambiguous.State.Strict as A
27+import qualified Control.Monad.Ether.State.Strict as A
30
28
31-- | See 'Control.Monad.Ether.State.Strict.StateT'.
29-- | See 'Control.Monad.Ether.State.Strict.StateT'.
32type StateT s = A.StateT s s
30type StateT s = A.StateT s s
src/Control/Monad/Ether/Implicit/Writer.hs+1−3
@@ -1,6 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE TypeApplications #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4
2
5-- | See "Control.Monad.Ether.Writer".
3-- | See "Control.Monad.Ether.Writer".
6
4
@@ -25,7 +23,7 @@ module Control.Monad.Ether.Implicit.Writer
25 , execWriterT
23 , execWriterT
26 ) where
24 ) where
27
25
28−import qualified Control.Monad.Ether.Ambiguous.Writer as A
26+import qualified Control.Monad.Ether.Writer as A
29
27
30-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
28-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
31type MonadWriter w = A.MonadWriter w w
29type MonadWriter w = A.MonadWriter w w
src/Control/Monad/Ether/Reader.hs+42−2
@@ -1,10 +1,15 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE MagicHash #-}
1
3
2-- | See "Control.Monad.Reader".
4-- | See "Control.Monad.Reader".
3
5
4module Control.Monad.Ether.Reader
6module Control.Monad.Ether.Reader
5 (
7 (
6 -- * MonadReader class
8 -- * MonadReader class
7− MonadReader(..)
9+ MonadReader
10+ , ask
11+ , local
12+ , reader
8 , asks
13 , asks
9 -- * The Reader monad
14 -- * The Reader monad
10 , Reader
15 , Reader
@@ -15,5 +20,40 @@ module Control.Monad.Ether.Reader
15 , runReaderT
20 , runReaderT
16 ) where
21 ) where
17
22
23+import GHC.Prim (Proxy#, proxy#)
18−import Control.Monad.Ether.Reader.Class
24+import Control.Monad.Ether.Reader.Class (MonadReader)
25+import qualified Control.Monad.Ether.Reader.Class as C
19import Control.Monad.Trans.Ether.Reader hiding (reader, ask, local)
26import 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 #-}
2{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE MagicHash #-}
4{-# LANGUAGE MagicHash #-}
8
5
9-- | See "Control.Monad.Reader.Class".
6-- | See "Control.Monad.Reader.Class".
10
7
11module Control.Monad.Ether.Reader.Class
8module Control.Monad.Ether.Reader.Class
12− ( MonadReader(..)
9+ ( MonadReader(..)
13− , asks
14− ) where
10+ ) where
15
11
16import GHC.Prim (Proxy#)
12import GHC.Prim (Proxy#)
17import qualified Control.Monad.Trans.Ether.Reader as R
13import qualified Control.Monad.Trans.Ether.Reader as R
@@ -43,19 +39,10 @@ class Monad m => MonadReader tag r m | m tag -> r where
43 -> m a
39 -> m a
44 reader t f = fmap f (ask t)
40 reader t f = fmap f (ask t)
45
41
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−
55instance (Monad m, r ~ r') => MonadReader tag r (R.ReaderT tag r' m) where
42instance (Monad m, r ~ r') => MonadReader tag r (R.ReaderT tag r' m) where
56− ask = R.ask
43+ ask _ = R.ask @tag
57− local = R.local
44+ local _ = R.local @tag
58− reader = R.reader
45+ reader _ = R.reader @tag
59
46
60instance {-# OVERLAPPABLE #-}
47instance {-# OVERLAPPABLE #-}
61 ( Lift.LiftLocal t
48 ( Lift.LiftLocal t
src/Control/Monad/Ether/State/Class.hs+8−21
@@ -1,18 +1,13 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
2{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE MagicHash #-}
4{-# LANGUAGE MagicHash #-}
8
5
9-- | See "Control.Monad.State.Class".
6-- | See "Control.Monad.State.Class".
10
7
11module Control.Monad.Ether.State.Class
8module Control.Monad.Ether.State.Class
12− ( MonadState(..)
9+ ( MonadState(..)
13− , modify
14− , gets
15− ) where
10+ ) where
16
11
17import GHC.Prim (Proxy#)
12import GHC.Prim (Proxy#)
18import qualified Control.Monad.Trans.Ether.State.Lazy as S.L
13import 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
40 put t s'
35 put t s'
41 return a
36 return a
42
37
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−
51instance (Monad m, s ~ s') => MonadState tag s (S.L.StateT tag s' m) where
38instance (Monad m, s ~ s') => MonadState tag s (S.L.StateT tag s' m) where
52− get = S.L.get
39+ get _ = S.L.get @tag
53− put = S.L.put
40+ put _ = S.L.put @tag
54− state = S.L.state
41+ state _ = S.L.state @tag
55
42
56instance (Monad m, s ~ s') => MonadState tag s (S.S.StateT tag s' m) where
43instance (Monad m, s ~ s') => MonadState tag s (S.S.StateT tag s' m) where
57− get = S.S.get
44+ get _ = S.S.get @tag
58− put = S.S.put
45+ put _ = S.S.put @tag
59− state = S.S.state
46+ state _ = S.S.state @tag
60
47
61instance {-# OVERLAPPABLE #-}
48instance {-# OVERLAPPABLE #-}
62 ( Lift.MonadTrans t
49 ( 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 @@
4module Control.Monad.Ether.State.Lazy
4module Control.Monad.Ether.State.Lazy
5 (
5 (
6 -- * MonadState class
6 -- * MonadState class
7− MonadState(..)
7+ MonadState
8+ , get
9+ , put
10+ , state
8 , modify
11 , modify
9 , gets
12 , gets
10 -- * The State monad
13 -- * The State monad
@@ -20,5 +23,5 @@ module Control.Monad.Ether.State.Lazy
20 , execStateT
23 , execStateT
21 ) where
24 ) where
22
25
23−import Control.Monad.Ether.State.Class
26+import Control.Monad.Ether.State.Common
24import Control.Monad.Trans.Ether.State.Lazy hiding (state, get, put)
27import Control.Monad.Trans.Ether.State.Lazy hiding (state, get, put)
src/Control/Monad/Ether/State/Strict.hs+5−2
@@ -4,7 +4,10 @@
4module Control.Monad.Ether.State.Strict
4module Control.Monad.Ether.State.Strict
5 (
5 (
6 -- * MonadState class
6 -- * MonadState class
7− MonadState(..)
7+ MonadState
8+ , get
9+ , put
10+ , state
8 , modify
11 , modify
9 , gets
12 , gets
10 -- * The State monad
13 -- * The State monad
@@ -20,5 +23,5 @@ module Control.Monad.Ether.State.Strict
20 , execStateT
23 , execStateT
21 ) where
24 ) where
22
25
23−import Control.Monad.Ether.State.Class
26+import Control.Monad.Ether.State.Common
24import Control.Monad.Trans.Ether.State.Strict hiding (state, get, put)
27import 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 #-}
1
3
2-- | See "Control.Monad.Writer".
4-- | See "Control.Monad.Writer".
3
5
4module Control.Monad.Ether.Writer
6module Control.Monad.Ether.Writer
5 (
7 (
6 -- * MonadWriter class
8 -- * MonadWriter class
7− MonadWriter(..)
9+ MonadWriter
10+ , writer
11+ , tell
12+ , listen
13+ , pass
8 , listens
14 , listens
9 , censor
15 , censor
10 -- * The Writer monad
16 -- * The Writer monad
@@ -18,5 +24,38 @@ module Control.Monad.Ether.Writer
18 , execWriterT
24 , execWriterT
19 ) where
25 ) where
20
26
27+import GHC.Prim (Proxy#, proxy#)
21−import Control.Monad.Ether.Writer.Class
28+import Control.Monad.Ether.Writer.Class (MonadWriter)
29+import qualified Control.Monad.Ether.Writer.Class as C
22import Control.Monad.Trans.Ether.Writer hiding (writer, tell, listen, pass)
30import 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 #-}
2{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE UndecidableInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE MagicHash #-}
4{-# LANGUAGE MagicHash #-}
8
5
9-- | See "Control.Monad.Writer.Class".
6-- | See "Control.Monad.Writer.Class".
10
7
11module Control.Monad.Ether.Writer.Class
8module Control.Monad.Ether.Writer.Class
12− ( MonadWriter(..)
9+ ( MonadWriter(..)
13− , listens
14− , censor
15− ) where
10+ ) where
16
11
17import GHC.Prim (Proxy#)
12import GHC.Prim (Proxy#)
18import qualified Control.Monad.Trans.Ether.Writer as W
13import 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
42 -- and return the value, applying the function to the accumulator.
37 -- and return the value, applying the function to the accumulator.
43 pass :: Proxy# tag -> m (a, w -> w) -> m a
38 pass :: Proxy# tag -> m (a, w -> w) -> m a
44
39
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−
58instance (Monoid w, Monad m, w ~ w') => MonadWriter tag w (W.WriterT tag w' m) where
40instance (Monoid w, Monad m, w ~ w') => MonadWriter tag w (W.WriterT tag w' m) where
59− writer = W.writer
41+ writer _ = W.writer @tag
60− tell = W.tell
42+ tell _ = W.tell @tag
61− listen = W.listen
43+ listen _ = W.listen @tag
62− pass = W.pass
44+ pass _ = W.pass @tag
63
45
64instance {-# OVERLAPPABLE #-}
46instance {-# OVERLAPPABLE #-}
65 ( Lift.LiftListen t
47 ( Lift.LiftListen t
src/Control/Monad/Trans/Ether/Dispatch.hs+25−25
@@ -1,15 +1,11 @@
1{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
1{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
2
2
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
7{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE UndecidableInstances #-}
8−{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE DataKinds #-}
10−{-# LANGUAGE PolyKinds #-}
11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12−{-# LANGUAGE MagicHash #-}
13
9
14{- |
10{- |
15
11
@@ -63,7 +59,6 @@ import Control.Monad.Morph (MFunctor, MMonad)
63import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
59import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
64import GHC.Generics (Generic)
60import GHC.Generics (Generic)
65import Data.Coerce (coerce)
61import Data.Coerce (coerce)
66−import GHC.Prim (Proxy#, proxy#)
67
62
68import qualified Control.Monad.Base as MB
63import qualified Control.Monad.Base as MB
69import qualified Control.Monad.Trans.Control as MC
64import qualified Control.Monad.Trans.Control as MC
@@ -81,6 +76,11 @@ import Control.Monad.Ether.State.Class
81import Control.Monad.Ether.Except.Class
76import Control.Monad.Ether.Except.Class
82import Control.Monad.Ether.Writer.Class
77import Control.Monad.Ether.Writer.Class
83
78
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+
84import qualified Control.Monad.Reader as Class
84import qualified Control.Monad.Reader as Class
85import qualified Control.Monad.State as Class
85import qualified Control.Monad.State as Class
86import qualified Control.Monad.Except as Class
86import qualified Control.Monad.Except as Class
@@ -156,47 +156,47 @@ tagReplace = coerce
156
156
157instance MonadReader tag r m
157instance MonadReader tag r m
158 => Class.MonadReader r (DispatchTagAttachT tag m) where
158 => Class.MonadReader r (DispatchTagAttachT tag m) where
159− ask = let t = proxy# :: Proxy# tag in Lift.lift (ask t)
159+ ask = Lift.lift (A.ask @tag)
160− local = let t = proxy# :: Proxy# tag in Lift.liftLocal (ask t) (local t)
160+ local = Lift.liftLocal (A.ask @tag) (A.local @tag)
161
161
162instance MonadState tag s m
162instance MonadState tag s m
163 => Class.MonadState s (DispatchTagAttachT tag m) where
163 => Class.MonadState s (DispatchTagAttachT tag m) where
164− get = let t = proxy# :: Proxy# tag in Lift.lift (get t)
164+ get = Lift.lift (A.get @tag)
165− put = let t = proxy# :: Proxy# tag in Lift.lift . put t
165+ put = Lift.lift . A.put @tag
166
166
167instance MonadExcept tag e m
167instance MonadExcept tag e m
168 => Class.MonadError e (DispatchTagAttachT tag m) where
168 => Class.MonadError e (DispatchTagAttachT tag m) where
169− throwError = let t = proxy# :: Proxy# tag in Lift.lift . throw t
169+ throwError = Lift.lift . A.throw @tag
170− catchError = let t = proxy# :: Proxy# tag in Lift.liftCatch (catch t)
170+ catchError = Lift.liftCatch (A.catch @tag)
171
171
172instance MonadWriter tag w m
172instance MonadWriter tag w m
173 => Class.MonadWriter w (DispatchTagAttachT tag m) where
173 => Class.MonadWriter w (DispatchTagAttachT tag m) where
174− writer = let t = proxy# :: Proxy# tag in Lift.lift . writer t
174+ writer = Lift.lift . A.writer @tag
175− tell = let t = proxy# :: Proxy# tag in Lift.lift . tell t
175+ tell = Lift.lift . A.tell @tag
176− listen = let t = proxy# :: Proxy# tag in Lift.liftListen (listen t)
176+ listen = Lift.liftListen (A.listen @tag)
177− pass = let t = proxy# :: Proxy# tag in Lift.liftPass (pass t)
177+ pass = Lift.liftPass (A.pass @tag)
178
178
179
179
180-- TagReplace instances
180-- TagReplace instances
181
181
182instance MonadReader tNew r m
182instance MonadReader tNew r m
183 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
183 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
184− ask _ = let t = proxy# :: Proxy# tNew in Lift.lift (ask t)
184+ ask _ = Lift.lift (A.ask @tNew)
185− local _ = let t = proxy# :: Proxy# tNew in Lift.liftLocal (ask t) (local t)
185+ local _ = Lift.liftLocal (A.ask @tNew) (A.local @tNew)
186
186
187instance MonadState tNew s m
187instance MonadState tNew s m
188 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
188 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
189− get _ = let t = proxy# :: Proxy# tNew in Lift.lift (get t)
189+ get _ = Lift.lift (A.get @tNew)
190− put _ = let t = proxy# :: Proxy# tNew in Lift.lift . put t
190+ put _ = Lift.lift . A.put @tNew
191
191
192instance MonadExcept tNew e m
192instance MonadExcept tNew e m
193 => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
193 => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
194− throw _ = let t = proxy# :: Proxy# tNew in Lift.lift . throw t
194+ throw _ = Lift.lift . A.throw @tNew
195− catch _ = let t = proxy# :: Proxy# tNew in Lift.liftCatch (catch t)
195+ catch _ = Lift.liftCatch (A.catch @tNew)
196
196
197instance MonadWriter tNew w m
197instance MonadWriter tNew w m
198 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
198 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
199− writer _ = let t = proxy# :: Proxy# tNew in Lift.lift . writer t
199+ writer _ = Lift.lift . A.writer @tNew
200− tell _ = let t = proxy# :: Proxy# tNew in Lift.lift . tell t
200+ tell _ = Lift.lift . A.tell @tNew
201− listen _ = let t = proxy# :: Proxy# tNew in Lift.liftListen (listen t)
201+ listen _ = Lift.liftListen (A.listen @tNew)
202− pass _ = let t = proxy# :: Proxy# tNew in Lift.liftPass (pass t)
202+ pass _ = Lift.liftPass (A.pass @tNew)
src/Control/Monad/Trans/Ether/Except.hs+15−16
@@ -1,12 +1,10 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
10
8
11-- | See "Control.Monad.Trans.Except".
9-- | See "Control.Monad.Trans.Except".
12
10
@@ -25,7 +23,6 @@ module Control.Monad.Trans.Ether.Except
25 , catch
23 , catch
26 ) where
24 ) where
27
25
28−import GHC.Prim (Proxy#)
29import Data.Functor.Identity (Identity(..))
26import Data.Functor.Identity (Identity(..))
30import qualified Control.Monad.Trans.Except as Trans
27import qualified Control.Monad.Trans.Except as Trans
31import Control.Monad.Trans.Ether.Tagged
28import Control.Monad.Trans.Ether.Tagged
@@ -40,8 +37,8 @@ import Control.Monad.Trans.Ether.Tagged
40type Except tag e = ExceptT tag e Identity
37type Except tag e = ExceptT tag e Identity
41
38
42-- | Runs an 'Except' and returns either an exception or a normal value.
39-- | Runs an 'Except' and returns either an exception or a normal value.
43−runExcept :: Proxy# tag -> Except tag e a -> Either e a
40+runExcept :: forall tag e a . Except tag e a -> Either e a
44−runExcept _ = Trans.runExcept . unpack
41+runExcept = Trans.runExcept . unpack
45
42
46-- | The exception monad transformer.
43-- | The exception monad transformer.
47--
44--
@@ -50,22 +47,24 @@ runExcept _ = Trans.runExcept . unpack
50type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
47type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
51
48
52-- | Constructor for computations in the exception monad transformer.
49-- | Constructor for computations in the exception monad transformer.
53−exceptT :: Proxy# tag -> m (Either e a) -> ExceptT tag e m a
50+exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
54−exceptT _ = pack . Trans.ExceptT
51+exceptT = pack . Trans.ExceptT
55
52
56-- | Constructor for computations in the exception monad
53-- | Constructor for computations in the exception monad
57-- (the inverse of 'runExcept').
54-- (the inverse of 'runExcept').
58−except :: Monad m => Proxy# tag -> Either e a -> ExceptT tag e m a
55+except :: forall tag e m a . Monad m => Either e a -> ExceptT tag e m a
59−except t = exceptT t . return
56+except = exceptT @tag . return
60
57
61-- | Runs an 'ExceptT' and returns either an exception or a normal value.
58-- | 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)
59+runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
63−runExceptT _ = Trans.runExceptT . unpack
60+runExceptT = Trans.runExceptT . unpack
64
61
65-- | Is used within a monadic computation to begin exception processing.
62-- | Is used within a monadic computation to begin exception processing.
66−throw :: Monad m => Proxy# tag -> e -> ExceptT tag e m a
63+throw :: forall tag e m a . Monad m => e -> ExceptT tag e m a
67−throw _ = pack . Trans.throwE
64+throw = pack . Trans.throwE
68
65
69-- | A handler function to handle previous exceptions and return to normal execution.
66-- | A handler function to handle previous exceptions and return to normal execution.
67+catch
68+ :: forall tag e m a . Monad m
70−catch :: Monad m => Proxy# tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
69+ => 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)
70+catch m h = pack $ Trans.catchE (unpack m) (unpack . h)
src/Control/Monad/Trans/Ether/Reader.hs+14−17
@@ -1,12 +1,10 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
10
8
11-- | See "Control.Monad.Trans.Reader".
9-- | See "Control.Monad.Trans.Reader".
12
10
@@ -25,7 +23,6 @@ module Control.Monad.Trans.Ether.Reader
25 , local
23 , local
26 ) where
24 ) where
27
25
28−import GHC.Prim (Proxy#)
29import Data.Functor.Identity (Identity(..))
26import Data.Functor.Identity (Identity(..))
30import qualified Control.Monad.Trans.Reader as Trans
27import qualified Control.Monad.Trans.Reader as Trans
31import Control.Monad.Trans.Ether.Tagged
28import Control.Monad.Trans.Ether.Tagged
@@ -46,37 +43,37 @@ type Reader tag r = ReaderT tag r Identity
46type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
43type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
47
44
48-- | Constructor for computations in the reader monad transformer.
45-- | Constructor for computations in the reader monad transformer.
49−readerT :: Proxy# tag -> (r -> m a) -> ReaderT tag r m a
46+readerT :: forall tag r m a . (r -> m a) -> ReaderT tag r m a
50−readerT _ = pack . Trans.ReaderT
47+readerT = pack . Trans.ReaderT
51
48
52-- | Constructor for computations in the reader monad
49-- | Constructor for computations in the reader monad
53-- (the inverse of 'runReader').
50-- (the inverse of 'runReader').
54−reader :: Monad m => Proxy# tag -> (r -> a) -> ReaderT tag r m a
51+reader :: forall tag r m a . Monad m => (r -> a) -> ReaderT tag r m a
55−reader _ = pack . Trans.reader
52+reader = pack . Trans.reader
56
53
57-- | Runs a 'ReaderT' with the given environment
54-- | Runs a 'ReaderT' with the given environment
58-- and returns the final value.
55-- and returns the final value.
59−runReaderT :: Proxy# tag -> ReaderT tag r m a -> r -> m a
56+runReaderT :: forall tag r m a . ReaderT tag r m a -> r -> m a
60−runReaderT _ = Trans.runReaderT . unpack
57+runReaderT = Trans.runReaderT . unpack
61
58
62-- | Runs a 'ReaderT' with the given environment
59-- | Runs a 'ReaderT' with the given environment
63-- and returns the final value.
60-- and returns the final value.
64−runReader :: Proxy# tag -> Reader tag r a -> r -> a
61+runReader :: forall tag r a . Reader tag r a -> r -> a
65−runReader _ = Trans.runReader . unpack
62+runReader = Trans.runReader . unpack
66
63
67-- | Fetch the value of the environment.
64-- | Fetch the value of the environment.
68−ask :: Monad m => Proxy# tag -> ReaderT tag r m r
65+ask :: forall tag r m . Monad m => ReaderT tag r m r
69−ask _ = pack Trans.ask
66+ask = pack Trans.ask
70
67
71-- | Execute a computation in a modified environment
68-- | Execute a computation in a modified environment
72-- (a specialization of 'withReaderT').
69-- (a specialization of 'withReaderT').
73--
70--
74-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
71-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
75local
72local
76− :: Proxy# tag
73+ :: forall tag r m a
77− -> (r -> r)
74+ . (r -> r)
78 -- ^ The function to modify the environment.
75 -- ^ The function to modify the environment.
79 -> ReaderT tag r m a
76 -> ReaderT tag r m a
80 -- ^ Computation to run in the modified environment.
77 -- ^ Computation to run in the modified environment.
81 -> ReaderT tag r m a
78 -> 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 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
10
8
11-- | See "Control.Monad.Trans.State.Lazy".
9-- | See "Control.Monad.Trans.State.Lazy".
12
10
@@ -29,7 +27,6 @@ module Control.Monad.Trans.Ether.State.Lazy
29 , put
27 , put
30 ) where
28 ) where
31
29
32−import GHC.Prim (Proxy#)
33import Data.Functor.Identity (Identity(..))
30import Data.Functor.Identity (Identity(..))
34import qualified Control.Monad.Trans.State.Lazy as Trans
31import qualified Control.Monad.Trans.State.Lazy as Trans
35import Control.Monad.Trans.Ether.Tagged
32import Control.Monad.Trans.Ether.Tagged
@@ -49,48 +46,48 @@ type State tag r = StateT tag r Identity
49type StateT tag s = TaggedTrans tag (Trans.StateT s)
46type StateT tag s = TaggedTrans tag (Trans.StateT s)
50
47
51-- | Constructor for computations in the state monad transformer.
48-- | Constructor for computations in the state monad transformer.
52−stateT :: Proxy# tag -> (s -> m (a, s)) -> StateT tag s m a
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
53−stateT _ = pack . Trans.StateT
50+stateT = pack . Trans.StateT
54
51
55-- | Constructor for computations in the state monad
52-- | Constructor for computations in the state monad
56-- (the inverse of 'runState').
53-- (the inverse of 'runState').
57−state :: Monad m => Proxy# tag -> (s -> (a, s)) -> StateT tag s m a
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
58−state _ = pack . Trans.state
55+state = pack . Trans.state
59
56
60-- | Runs a 'StateT' with the given initial state
57-- | Runs a 'StateT' with the given initial state
61-- and returns both the final value and the final state.
58-- and returns both the final value and the final state.
62−runStateT :: Proxy# tag -> StateT tag s m a -> s -> m (a, s)
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
63−runStateT _ = Trans.runStateT . unpack
60+runStateT = Trans.runStateT . unpack
64
61
65-- | Runs a 'StateT' with the given initial state
62-- | Runs a 'StateT' with the given initial state
66-- and returns the final value, discarding the final state.
63-- and returns the final value, discarding the final state.
67−evalStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m a
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
68−evalStateT _ = Trans.evalStateT . unpack
65+evalStateT = Trans.evalStateT . unpack
69
66
70-- | Runs a 'StateT' with the given initial state
67-- | Runs a 'StateT' with the given initial state
71-- and returns the final state, discarding the final value.
68-- and returns the final state, discarding the final value.
72−execStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m s
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
73−execStateT _ = Trans.execStateT . unpack
70+execStateT = Trans.execStateT . unpack
74
71
75-- | Runs a 'State' with the given initial state
72-- | Runs a 'State' with the given initial state
76-- and returns both the final value and the final state.
73-- and returns both the final value and the final state.
77−runState :: Proxy# tag -> State tag s a -> s -> (a, s)
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
78−runState _ = Trans.runState . unpack
75+runState = Trans.runState . unpack
79
76
80-- | Runs a 'State' with the given initial state
77-- | Runs a 'State' with the given initial state
81-- and returns the final value, discarding the final state.
78-- and returns the final value, discarding the final state.
82−evalState :: Proxy# tag -> State tag s a -> s -> a
79+evalState :: forall tag s a . State tag s a -> s -> a
83−evalState _ = Trans.evalState . unpack
80+evalState = Trans.evalState . unpack
84
81
85-- | Runs a 'State' with the given initial state
82-- | Runs a 'State' with the given initial state
86-- and returns the final state, discarding the final value.
83-- and returns the final state, discarding the final value.
87−execState :: Proxy# tag -> State tag s a -> s -> s
84+execState :: forall tag s a . State tag s a -> s -> s
88−execState _ = Trans.execState . unpack
85+execState = Trans.execState . unpack
89
86
90-- | Fetch the current value of the state within the monad.
87-- | Fetch the current value of the state within the monad.
91−get :: Monad m => Proxy# tag -> StateT tag s m s
88+get :: forall tag s m . Monad m => StateT tag s m s
92−get _ = pack Trans.get
89+get = pack Trans.get
93
90
94-- | Set the value of the state within the monad.
91-- | Set the value of the state within the monad.
95−put :: Monad m => Proxy# tag -> s -> StateT tag s m ()
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
96−put _ = pack . Trans.put
93+put = pack . Trans.put
src/Control/Monad/Trans/Ether/State/Strict.hs+21−24
@@ -1,12 +1,10 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
10
8
11-- | See "Control.Monad.Trans.State.Strict".
9-- | See "Control.Monad.Trans.State.Strict".
12
10
@@ -29,7 +27,6 @@ module Control.Monad.Trans.Ether.State.Strict
29 , put
27 , put
30 ) where
28 ) where
31
29
32−import GHC.Prim (Proxy#)
33import Data.Functor.Identity (Identity(..))
30import Data.Functor.Identity (Identity(..))
34import qualified Control.Monad.Trans.State.Strict as Trans
31import qualified Control.Monad.Trans.State.Strict as Trans
35import Control.Monad.Trans.Ether.Tagged
32import Control.Monad.Trans.Ether.Tagged
@@ -49,48 +46,48 @@ type State tag r = StateT tag r Identity
49type StateT tag s = TaggedTrans tag (Trans.StateT s)
46type StateT tag s = TaggedTrans tag (Trans.StateT s)
50
47
51-- | Constructor for computations in the state monad transformer.
48-- | Constructor for computations in the state monad transformer.
52−stateT :: Proxy# tag -> (s -> m (a, s)) -> StateT tag s m a
49+stateT :: forall tag s m a . (s -> m (a, s)) -> StateT tag s m a
53−stateT _ = pack . Trans.StateT
50+stateT = pack . Trans.StateT
54
51
55-- | Constructor for computations in the state monad
52-- | Constructor for computations in the state monad
56-- (the inverse of 'runState').
53-- (the inverse of 'runState').
57−state :: Monad m => Proxy# tag -> (s -> (a, s)) -> StateT tag s m a
54+state :: forall tag s m a . Monad m => (s -> (a, s)) -> StateT tag s m a
58−state _ = pack . Trans.state
55+state = pack . Trans.state
59
56
60-- | Runs a 'StateT' with the given initial state
57-- | Runs a 'StateT' with the given initial state
61-- and returns both the final value and the final state.
58-- and returns both the final value and the final state.
62−runStateT :: Proxy# tag -> StateT tag s m a -> s -> m (a, s)
59+runStateT :: forall tag s m a . StateT tag s m a -> s -> m (a, s)
63−runStateT _ = Trans.runStateT . unpack
60+runStateT = Trans.runStateT . unpack
64
61
65-- | Runs a 'StateT' with the given initial state
62-- | Runs a 'StateT' with the given initial state
66-- and returns the final value, discarding the final state.
63-- and returns the final value, discarding the final state.
67−evalStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m a
64+evalStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m a
68−evalStateT _ = Trans.evalStateT . unpack
65+evalStateT = Trans.evalStateT . unpack
69
66
70-- | Runs a 'StateT' with the given initial state
67-- | Runs a 'StateT' with the given initial state
71-- and returns the final state, discarding the final value.
68-- and returns the final state, discarding the final value.
72−execStateT :: Monad m => Proxy# tag -> StateT tag s m a -> s -> m s
69+execStateT :: forall tag s m a . Monad m => StateT tag s m a -> s -> m s
73−execStateT _ = Trans.execStateT . unpack
70+execStateT = Trans.execStateT . unpack
74
71
75-- | Runs a 'State' with the given initial state
72-- | Runs a 'State' with the given initial state
76-- and returns both the final value and the final state.
73-- and returns both the final value and the final state.
77−runState :: Proxy# tag -> State tag s a -> s -> (a, s)
74+runState :: forall tag s a . State tag s a -> s -> (a, s)
78−runState _ = Trans.runState . unpack
75+runState = Trans.runState . unpack
79
76
80-- | Runs a 'State' with the given initial state
77-- | Runs a 'State' with the given initial state
81-- and returns the final value, discarding the final state.
78-- and returns the final value, discarding the final state.
82−evalState :: Proxy# tag -> State tag s a -> s -> a
79+evalState :: forall tag s a . State tag s a -> s -> a
83−evalState _ = Trans.evalState . unpack
80+evalState = Trans.evalState . unpack
84
81
85-- | Runs a 'State' with the given initial state
82-- | Runs a 'State' with the given initial state
86-- and returns the final state, discarding the final value.
83-- and returns the final state, discarding the final value.
87−execState :: Proxy# tag -> State tag s a -> s -> s
84+execState :: forall tag s a . State tag s a -> s -> s
88−execState _ = Trans.execState . unpack
85+execState = Trans.execState . unpack
89
86
90-- | Fetch the current value of the state within the monad.
87-- | Fetch the current value of the state within the monad.
91−get :: Monad m => Proxy# tag -> StateT tag s m s
88+get :: forall tag s m . Monad m => StateT tag s m s
92−get _ = pack Trans.get
89+get = pack Trans.get
93
90
94-- | Set the value of the state within the monad.
91-- | Set the value of the state within the monad.
95−put :: Monad m => Proxy# tag -> s -> StateT tag s m ()
92+put :: forall tag s m . Monad m => s -> StateT tag s m ()
96−put _ = pack . Trans.put
93+put = pack . Trans.put
src/Control/Monad/Trans/Ether/Tagged.hs−2
@@ -1,8 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE PolyKinds #-}
5−{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
7{-# LANGUAGE ConstraintKinds #-}
5{-# LANGUAGE ConstraintKinds #-}
8{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE TypeFamilies #-}
src/Control/Monad/Trans/Ether/Writer.hs+19−22
@@ -1,12 +1,10 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7−{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9−{-# LANGUAGE MagicHash #-}
7+{-# LANGUAGE AllowAmbiguousTypes #-}
10
8
11-- | See "Control.Monad.Trans.Writer".
9-- | See "Control.Monad.Trans.Writer".
12
10
@@ -28,7 +26,6 @@ module Control.Monad.Trans.Ether.Writer
28 , pass
26 , pass
29 ) where
27 ) where
30
28
31−import GHC.Prim (Proxy#)
32import Data.Functor.Identity (Identity(..))
29import Data.Functor.Identity (Identity(..))
33import qualified Control.Monad.Trans.Writer.Lazy as Trans
30import qualified Control.Monad.Trans.Writer.Lazy as Trans
34import Control.Monad.Trans.Ether.Tagged
31import Control.Monad.Trans.Ether.Tagged
@@ -48,43 +45,43 @@ type Writer tag w = WriterT tag w Identity
48type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
45type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
49
46
50-- | Constructor for computations in the writer monad transformer.
47-- | Constructor for computations in the writer monad transformer.
51−writerT :: Proxy# tag -> m (a, w) -> WriterT tag w m a
48+writerT :: forall tag w m a . m (a, w) -> WriterT tag w m a
52−writerT _ = pack . Trans.WriterT
49+writerT = pack . Trans.WriterT
53
50
54-- | Constructor for computations in the writer monad
51-- | Constructor for computations in the writer monad
55-- (the inverse of 'runWriter').
52-- (the inverse of 'runWriter').
56−writer :: Monad m => Proxy# tag -> (a, w) -> WriterT tag w m a
53+writer :: forall tag w m a . Monad m => (a, w) -> WriterT tag w m a
57−writer _ = pack . Trans.writer
54+writer = pack . Trans.writer
58
55
59-- | Runs a 'WriterT' and returns both the normal value
56-- | Runs a 'WriterT' and returns both the normal value
60-- and the final accumulator.
57-- and the final accumulator.
61−runWriterT :: Proxy# tag -> WriterT tag w m a -> m (a, w)
58+runWriterT :: forall tag w m a . WriterT tag w m a -> m (a, w)
62−runWriterT _ = Trans.runWriterT . unpack
59+runWriterT = Trans.runWriterT . unpack
63
60
64-- | Runs a 'Writer' and returns both the normal value
61-- | Runs a 'Writer' and returns both the normal value
65-- and the final accumulator.
62-- and the final accumulator.
66−runWriter :: Proxy# tag -> Writer tag w a -> (a, w)
63+runWriter :: forall tag w a . Writer tag w a -> (a, w)
67−runWriter _ = Trans.runWriter . unpack
64+runWriter = Trans.runWriter . unpack
68
65
69-- | Runs a 'WriterT' and returns the final accumulator,
66-- | Runs a 'WriterT' and returns the final accumulator,
70-- discarding the normal value.
67-- discarding the normal value.
71−execWriterT :: Monad m => Proxy# tag -> WriterT tag w m a -> m w
68+execWriterT :: forall tag w m a . Monad m => WriterT tag w m a -> m w
72−execWriterT _ = Trans.execWriterT . unpack
69+execWriterT = Trans.execWriterT . unpack
73
70
74-- | Runs a 'Writer' and returns the final accumulator,
71-- | Runs a 'Writer' and returns the final accumulator,
75-- discarding the normal value.
72-- discarding the normal value.
76−execWriter :: Proxy# tag -> Writer tag w a -> w
73+execWriter :: forall tag w a . Writer tag w a -> w
77−execWriter _ = Trans.execWriter . unpack
74+execWriter = Trans.execWriter . unpack
78
75
79-- | Appends a value to the accumulator within the monad.
76-- | Appends a value to the accumulator within the monad.
80−tell :: Monad m => Proxy# tag -> w -> WriterT tag w m ()
77+tell :: forall tag w m . Monad m => w -> WriterT tag w m ()
81−tell t w = writer t ((), w)
78+tell w = writer @tag ((), w)
82
79
83-- | Executes an action and adds its accumulator to the value of the computation.
80-- | 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)
81+listen :: forall tag w m a . Monad m => WriterT tag w m a -> WriterT tag w m (a, w)
85−listen _ = pack . Trans.listen . unpack
82+listen = pack . Trans.listen . unpack
86
83
87-- | Executes an action which returns a value and a function, and returns the
84-- | Executes an action which returns a value and a function, and returns the
88-- value, applying the function to the accumulator.
85-- 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
86+pass :: forall tag w m a . Monad m => WriterT tag w m (a, w -> w) -> WriterT tag w m a
90−pass _ = pack . Trans.pass . unpack
87+pass = pack . Trans.pass . unpack
test/Regression/T1.hs+1−1
@@ -1,6 +1,6 @@
1module Regression.T1 (test1) where
1module Regression.T1 (test1) where
2
2
3−import Control.Monad.Ether.Ambiguous
3+import Control.Monad.Ether
4import Control.Ether.Abbr
4import Control.Ether.Abbr
5
5
6import Test.Tasty
6import Test.Tasty
test/Regression/T3.hs+1−1
@@ -1,7 +1,7 @@
1module Regression.T3 (test3) where
1module Regression.T3 (test3) where
2
2
3import Control.Ether.Abbr
3import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
5
5
6import qualified Control.Monad.Reader as T
6import qualified Control.Monad.Reader as T
7import qualified Control.Monad.State as T
7import qualified Control.Monad.State as T
test/Regression/T4.hs+1−1
@@ -1,7 +1,7 @@
1module Regression.T4 (test4) where
1module Regression.T4 (test4) where
2
2
3import Control.Ether.Abbr
3import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
5
5
6import Test.Tasty
6import Test.Tasty
7import Test.Tasty.QuickCheck
7import Test.Tasty.QuickCheck
test/Regression/T7.hs+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 Control.Monad.Ether.Ambiguous
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+1−1
@@ -1,7 +1,7 @@
1module Regression.T8 (test8) where
1module Regression.T8 (test8) where
2
2
3import Control.Ether.Abbr
3import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
5
5
6import qualified Control.Monad.State as T
6import qualified Control.Monad.State as T
7
7
test/Regression/T9.hs+1−1
@@ -1,7 +1,7 @@
1module Regression.T9 (test9) where
1module Regression.T9 (test9) where
2
2
3import Control.Ether.Abbr
3import Control.Ether.Abbr
4−import Control.Monad.Ether.Ambiguous
4+import Control.Monad.Ether
5
5
6import Test.Tasty
6import Test.Tasty
7import Test.Tasty.QuickCheck
7import Test.Tasty.QuickCheck