on master help sign in
Proxy-hash for MonadReader
cdd0909Index Int
src/Control/Monad/Ether/Except/Class.hs+1−1
@@ -19,7 +19,7 @@ module Control.Monad.Ether.Except.Class
19 ( MonadExcept(..)
19 ( MonadExcept(..)
20 ) where
20 ) where
21
21
22−import GHC.Prim (Proxy#, proxy#)
22+import GHC.Prim (Proxy#)
23import qualified Control.Monad.Trans.Ether.Except as E
23import qualified Control.Monad.Trans.Ether.Except as E
24import qualified Control.Monad.Trans.Lift.Catch as Lift
24import qualified Control.Monad.Trans.Lift.Catch as Lift
25
25
src/Control/Monad/Ether/Implicit/Reader.hs+9−8
@@ -1,5 +1,6 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MagicHash #-}
3
4
4-- | See "Control.Monad.Ether.Reader".
5-- | See "Control.Monad.Ether.Reader".
5
6
@@ -20,7 +21,7 @@ module Control.Monad.Ether.Implicit.Reader
20 , runReaderT
21 , runReaderT
21 ) where
22 ) where
22
23
23−import Data.Proxy
24+import GHC.Prim (Proxy#, proxy#)
24import qualified Control.Monad.Ether.Reader as Explicit
25import qualified Control.Monad.Ether.Reader as Explicit
25
26
26-- | See 'Control.Monad.Ether.Reader.ReaderT'.
27-- | See 'Control.Monad.Ether.Reader.ReaderT'.
@@ -31,31 +32,31 @@ type Reader r = Explicit.Reader r r
31
32
32-- | See 'Control.Monad.Ether.Reader.readerT'.
33-- | See 'Control.Monad.Ether.Reader.readerT'.
33readerT :: (r -> m a) -> ReaderT r m a
34readerT :: (r -> m a) -> ReaderT r m a
34−readerT = Explicit.readerT Proxy
35+readerT = Explicit.readerT proxy#
35
36
36-- | See 'Control.Monad.Ether.Reader.runReaderT'.
37-- | See 'Control.Monad.Ether.Reader.runReaderT'.
37runReaderT :: ReaderT r m a -> r -> m a
38runReaderT :: ReaderT r m a -> r -> m a
38−runReaderT = Explicit.runReaderT Proxy
39+runReaderT = Explicit.runReaderT proxy#
39
40
40-- | See 'Control.Monad.Ether.Reader.runReader'.
41-- | See 'Control.Monad.Ether.Reader.runReader'.
41runReader :: Reader r a -> r -> a
42runReader :: Reader r a -> r -> a
42−runReader = Explicit.runReader Proxy
43+runReader = Explicit.runReader proxy#
43
44
44-- | See 'Control.Monad.Ether.Reader.MonadReader'.
45-- | See 'Control.Monad.Ether.Reader.MonadReader'.
45type MonadReader r = Explicit.MonadReader r r
46type MonadReader r = Explicit.MonadReader r r
46
47
47-- | See 'Control.Monad.Ether.Reader.local'.
48-- | See 'Control.Monad.Ether.Reader.local'.
48local :: forall r m a . MonadReader r m => (r -> r) -> m a -> m a
49local :: forall r m a . MonadReader r m => (r -> r) -> m a -> m a
49−local = Explicit.local (Proxy :: Proxy r)
50+local = Explicit.local (proxy# :: Proxy# r)
50
51
51-- | See 'Control.Monad.Ether.Reader.ask'.
52-- | See 'Control.Monad.Ether.Reader.ask'.
52ask :: forall r m . MonadReader r m => m r
53ask :: forall r m . MonadReader r m => m r
53−ask = Explicit.ask (Proxy :: Proxy r)
54+ask = Explicit.ask (proxy# :: Proxy# r)
54
55
55-- | See 'Control.Monad.Ether.Reader.reader'.
56-- | See 'Control.Monad.Ether.Reader.reader'.
56reader :: forall r m a . MonadReader r m => (r -> a) -> m a
57reader :: forall r m a . MonadReader r m => (r -> a) -> m a
57−reader = Explicit.reader (Proxy :: Proxy r)
58+reader = Explicit.reader (proxy# :: Proxy# r)
58
59
59-- | See 'Control.Monad.Ether.Reader.asks'.
60-- | See 'Control.Monad.Ether.Reader.asks'.
60asks :: forall r m a . MonadReader r m => (r -> a) -> m a
61asks :: forall r m a . MonadReader r m => (r -> a) -> m a
61−asks = Explicit.asks (Proxy :: Proxy r)
62+asks = Explicit.asks (proxy# :: Proxy# r)
src/Control/Monad/Ether/Reader/Class.hs+6−4
@@ -11,6 +11,7 @@
11{-# LANGUAGE FunctionalDependencies #-}
11{-# LANGUAGE FunctionalDependencies #-}
12{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE TypeFamilies #-}
13{-# LANGUAGE PolyKinds #-}
13{-# LANGUAGE PolyKinds #-}
14+{-# LANGUAGE MagicHash #-}
14
15
15-- | See "Control.Monad.Reader.Class".
16-- | See "Control.Monad.Reader.Class".
16
17
@@ -19,6 +20,7 @@ module Control.Monad.Ether.Reader.Class
19 , asks
20 , asks
20 ) where
21 ) where
21
22
23+import GHC.Prim (Proxy#)
22import qualified Control.Monad.Trans.Ether.Reader as R
24import qualified Control.Monad.Trans.Ether.Reader as R
23import qualified Control.Monad.Trans.Lift.Local as Lift
25import qualified Control.Monad.Trans.Lift.Local as Lift
24import qualified Control.Ether.Util as Util
26import qualified Control.Ether.Util as Util
@@ -29,12 +31,12 @@ class Monad m => MonadReader tag r m | m tag -> r where
29 {-# MINIMAL (ask | reader), local #-}
31 {-# MINIMAL (ask | reader), local #-}
30
32
31 -- | Retrieves the monad environment.
33 -- | Retrieves the monad environment.
32− ask :: proxy tag -> m r
34+ ask :: Proxy# tag -> m r
33 ask t = reader t id
35 ask t = reader t id
34
36
35 -- | Executes a computation in a modified environment.
37 -- | Executes a computation in a modified environment.
36 local
38 local
37− :: proxy tag
39+ :: Proxy# tag
38 -> (r -> r)
40 -> (r -> r)
39 -- ^ The function to modify the environment.
41 -- ^ The function to modify the environment.
40 -> m a
42 -> m a
@@ -43,7 +45,7 @@ class Monad m => MonadReader tag r m | m tag -> r where
43
45
44 -- | Retrieves a function of the current environment.
46 -- | Retrieves a function of the current environment.
45 reader
47 reader
46− :: proxy tag
48+ :: Proxy# tag
47 -> (r -> a)
49 -> (r -> a)
48 -- ^ The selector function to apply to the environment.
50 -- ^ The selector function to apply to the environment.
49 -> m a
51 -> m a
@@ -52,7 +54,7 @@ class Monad m => MonadReader tag r m | m tag -> r where
52-- | Retrieves a function of the current environment.
54-- | Retrieves a function of the current environment.
53asks
55asks
54 :: MonadReader tag r m
56 :: MonadReader tag r m
55− => proxy tag
57+ => Proxy# tag
56 -> (r -> a)
58 -> (r -> a)
57 -- ^ The selector function to apply to the environment.
59 -- ^ The selector function to apply to the environment.
58 -> m a
60 -> m a
src/Control/Monad/Trans/Ether/Dispatch.hs+4−4
@@ -165,8 +165,8 @@ tagReplace _ _ = coerce
165
165
166instance MonadReader tag r m
166instance MonadReader tag r m
167 => Class.MonadReader r (DispatchTagAttachT tag m) where
167 => Class.MonadReader r (DispatchTagAttachT tag m) where
168− ask = let t = Proxy :: Proxy tag in Lift.lift (ask t)
168+ ask = let t = proxy# :: Proxy# tag in Lift.lift (ask t)
169− local = let t = Proxy :: Proxy tag in Lift.liftLocal (ask t) (local t)
169+ local = let t = proxy# :: Proxy# tag in Lift.liftLocal (ask t) (local t)
170
170
171instance MonadState tag s m
171instance MonadState tag s m
172 => Class.MonadState s (DispatchTagAttachT tag m) where
172 => Class.MonadState s (DispatchTagAttachT tag m) where
@@ -190,8 +190,8 @@ instance MonadWriter tag w m
190
190
191instance MonadReader tNew r m
191instance MonadReader tNew r m
192 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
192 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
193− ask _ = let t = Proxy :: Proxy tNew in Lift.lift (ask t)
193+ ask _ = let t = proxy# :: Proxy# tNew in Lift.lift (ask t)
194− local _ = let t = Proxy :: Proxy tNew in Lift.liftLocal (ask t) (local t)
194+ local _ = let t = proxy# :: Proxy# tNew in Lift.liftLocal (ask t) (local t)
195
195
196instance MonadState tNew s m
196instance MonadState tNew s m
197 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
197 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
src/Control/Monad/Trans/Ether/Reader.hs+8−6
@@ -6,6 +6,7 @@
6{-# LANGUAGE DataKinds #-}
6{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+{-# LANGUAGE MagicHash #-}
9
10
10-- | See "Control.Monad.Trans.Reader".
11-- | See "Control.Monad.Trans.Reader".
11
12
@@ -24,6 +25,7 @@ module Control.Monad.Trans.Ether.Reader
24 , local
25 , local
25 ) where
26 ) where
26
27
28+import GHC.Prim (Proxy#)
27import Data.Functor.Identity (Identity(..))
29import Data.Functor.Identity (Identity(..))
28import qualified Control.Monad.Trans.Reader as Trans
30import qualified Control.Monad.Trans.Reader as Trans
29import Control.Monad.Trans.Ether.Tagged
31import Control.Monad.Trans.Ether.Tagged
@@ -44,26 +46,26 @@ type Reader tag r = ReaderT tag r Identity
44type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
46type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
45
47
46-- | Constructor for computations in the reader monad transformer.
48-- | Constructor for computations in the reader monad transformer.
47−readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a
49+readerT :: Proxy# tag -> (r -> m a) -> ReaderT tag r m a
48readerT _ = pack . Trans.ReaderT
50readerT _ = pack . Trans.ReaderT
49
51
50-- | Constructor for computations in the reader monad
52-- | Constructor for computations in the reader monad
51-- (the inverse of 'runReader').
53-- (the inverse of 'runReader').
52−reader :: Monad m => proxy tag -> (r -> a) -> ReaderT tag r m a
54+reader :: Monad m => Proxy# tag -> (r -> a) -> ReaderT tag r m a
53reader _ = pack . Trans.reader
55reader _ = pack . Trans.reader
54
56
55-- | Runs a 'ReaderT' with the given environment
57-- | Runs a 'ReaderT' with the given environment
56-- and returns the final value.
58-- and returns the final value.
57−runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a
59+runReaderT :: Proxy# tag -> ReaderT tag r m a -> r -> m a
58runReaderT _ = Trans.runReaderT . unpack
60runReaderT _ = Trans.runReaderT . unpack
59
61
60-- | Runs a 'ReaderT' with the given environment
62-- | Runs a 'ReaderT' with the given environment
61-- and returns the final value.
63-- and returns the final value.
62−runReader :: proxy tag -> Reader tag r a -> r -> a
64+runReader :: Proxy# tag -> Reader tag r a -> r -> a
63runReader _ = Trans.runReader . unpack
65runReader _ = Trans.runReader . unpack
64
66
65-- | Fetch the value of the environment.
67-- | Fetch the value of the environment.
66−ask :: Monad m => proxy tag -> ReaderT tag r m r
68+ask :: Monad m => Proxy# tag -> ReaderT tag r m r
67ask _ = pack Trans.ask
69ask _ = pack Trans.ask
68
70
69-- | Execute a computation in a modified environment
71-- | Execute a computation in a modified environment
@@ -71,7 +73,7 @@ ask _ = pack Trans.ask
71--
73--
72-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
74-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
73local
75local
74− :: proxy tag
76+ :: Proxy# tag
75 -> (r -> r)
77 -> (r -> r)
76 -- ^ The function to modify the environment.
78 -- ^ The function to modify the environment.
77 -> ReaderT tag r m a
79 -> ReaderT tag r m a