on master help sign in
Proxy-hash for MonadReader
commitcdd0909f0a76fb77c8341db50d947197797650c9 authorIndex Int <vlad.z.4096@gmail.com> dateSat 30 Apr 2016, 13:32 (10 years ago) parentda8edd9
5 files changed+28−23
src/Control/Monad/Ether/Except/Class.hs+1−1 src/Control/Monad/Ether/Implicit/Reader.hs+9−8 src/Control/Monad/Ether/Reader/Class.hs+6−4 src/Control/Monad/Trans/Ether/Dispatch.hs+4−4 src/Control/Monad/Trans/Ether/Reader.hs+8−6
src/Control/Monad/Ether/Except/Class.hs+1−1
@@ -19,7 +19,7 @@ module Control.Monad.Ether.Except.Class
1919 ( MonadExcept(..)
2020 ) where
2121
22−import GHC.Prim (Proxy#, proxy#)
22+import GHC.Prim (Proxy#)
2323import qualified Control.Monad.Trans.Ether.Except as E
2424import qualified Control.Monad.Trans.Lift.Catch as Lift
2525
src/Control/Monad/Ether/Implicit/Reader.hs+9−8
@@ -1,5 +1,6 @@
11{-# LANGUAGE ConstraintKinds #-}
22{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MagicHash #-}
34
45-- | See "Control.Monad.Ether.Reader".
56
@@ -20,7 +21,7 @@ module Control.Monad.Ether.Implicit.Reader
2021 , runReaderT
2122 ) where
2223
23−import Data.Proxy
24+import GHC.Prim (Proxy#, proxy#)
2425import qualified Control.Monad.Ether.Reader as Explicit
2526
2627-- | See 'Control.Monad.Ether.Reader.ReaderT'.
@@ -31,31 +32,31 @@ type Reader r = Explicit.Reader r r
3132
3233-- | See 'Control.Monad.Ether.Reader.readerT'.
3334readerT :: (r -> m a) -> ReaderT r m a
34−readerT = Explicit.readerT Proxy
35+readerT = Explicit.readerT proxy#
3536
3637-- | See 'Control.Monad.Ether.Reader.runReaderT'.
3738runReaderT :: ReaderT r m a -> r -> m a
38−runReaderT = Explicit.runReaderT Proxy
39+runReaderT = Explicit.runReaderT proxy#
3940
4041-- | See 'Control.Monad.Ether.Reader.runReader'.
4142runReader :: Reader r a -> r -> a
42−runReader = Explicit.runReader Proxy
43+runReader = Explicit.runReader proxy#
4344
4445-- | See 'Control.Monad.Ether.Reader.MonadReader'.
4546type MonadReader r = Explicit.MonadReader r r
4647
4748-- | See 'Control.Monad.Ether.Reader.local'.
4849local :: 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)
5051
5152-- | See 'Control.Monad.Ether.Reader.ask'.
5253ask :: forall r m . MonadReader r m => m r
53−ask = Explicit.ask (Proxy :: Proxy r)
54+ask = Explicit.ask (proxy# :: Proxy# r)
5455
5556-- | See 'Control.Monad.Ether.Reader.reader'.
5657reader :: 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)
5859
5960-- | See 'Control.Monad.Ether.Reader.asks'.
6061asks :: 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 @@
1111{-# LANGUAGE FunctionalDependencies #-}
1212{-# LANGUAGE TypeFamilies #-}
1313{-# LANGUAGE PolyKinds #-}
14+{-# LANGUAGE MagicHash #-}
1415
1516-- | See "Control.Monad.Reader.Class".
1617
@@ -19,6 +20,7 @@ module Control.Monad.Ether.Reader.Class
1920 , asks
2021 ) where
2122
23+import GHC.Prim (Proxy#)
2224import qualified Control.Monad.Trans.Ether.Reader as R
2325import qualified Control.Monad.Trans.Lift.Local as Lift
2426import qualified Control.Ether.Util as Util
@@ -29,12 +31,12 @@ class Monad m => MonadReader tag r m | m tag -> r where
2931 {-# MINIMAL (ask | reader), local #-}
3032
3133 -- | Retrieves the monad environment.
32− ask :: proxy tag -> m r
34+ ask :: Proxy# tag -> m r
3335 ask t = reader t id
3436
3537 -- | Executes a computation in a modified environment.
3638 local
37− :: proxy tag
39+ :: Proxy# tag
3840 -> (r -> r)
3941 -- ^ The function to modify the environment.
4042 -> m a
@@ -43,7 +45,7 @@ class Monad m => MonadReader tag r m | m tag -> r where
4345
4446 -- | Retrieves a function of the current environment.
4547 reader
46− :: proxy tag
48+ :: Proxy# tag
4749 -> (r -> a)
4850 -- ^ The selector function to apply to the environment.
4951 -> m a
@@ -52,7 +54,7 @@ class Monad m => MonadReader tag r m | m tag -> r where
5254-- | Retrieves a function of the current environment.
5355asks
5456 :: MonadReader tag r m
55− => proxy tag
57+ => Proxy# tag
5658 -> (r -> a)
5759 -- ^ The selector function to apply to the environment.
5860 -> m a
src/Control/Monad/Trans/Ether/Dispatch.hs+4−4
@@ -165,8 +165,8 @@ tagReplace _ _ = coerce
165165
166166instance MonadReader tag r m
167167 => Class.MonadReader r (DispatchTagAttachT tag m) where
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)
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)
170170
171171instance MonadState tag s m
172172 => Class.MonadState s (DispatchTagAttachT tag m) where
@@ -190,8 +190,8 @@ instance MonadWriter tag w m
190190
191191instance MonadReader tNew r m
192192 => MonadReader tOld r (DispatchTagReplaceT tOld tNew m) where
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)
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)
195195
196196instance MonadState tNew s m
197197 => MonadState tOld s (DispatchTagReplaceT tOld tNew m) where
src/Control/Monad/Trans/Ether/Reader.hs+8−6
@@ -6,6 +6,7 @@
66{-# LANGUAGE DataKinds #-}
77{-# LANGUAGE PolyKinds #-}
88{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+{-# LANGUAGE MagicHash #-}
910
1011-- | See "Control.Monad.Trans.Reader".
1112
@@ -24,6 +25,7 @@ module Control.Monad.Trans.Ether.Reader
2425 , local
2526 ) where
2627
28+import GHC.Prim (Proxy#)
2729import Data.Functor.Identity (Identity(..))
2830import qualified Control.Monad.Trans.Reader as Trans
2931import Control.Monad.Trans.Ether.Tagged
@@ -44,26 +46,26 @@ type Reader tag r = ReaderT tag r Identity
4446type ReaderT tag r = TaggedTrans tag (Trans.ReaderT r)
4547
4648-- | 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
4850readerT _ = pack . Trans.ReaderT
4951
5052-- | Constructor for computations in the reader monad
5153-- (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
5355reader _ = pack . Trans.reader
5456
5557-- | Runs a 'ReaderT' with the given environment
5658-- 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
5860runReaderT _ = Trans.runReaderT . unpack
5961
6062-- | Runs a 'ReaderT' with the given environment
6163-- 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
6365runReader _ = Trans.runReader . unpack
6466
6567-- | 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
6769ask _ = pack Trans.ask
6870
6971-- | Execute a computation in a modified environment
@@ -71,7 +73,7 @@ ask _ = pack Trans.ask
7173--
7274-- * @'runReaderT' tag ('local' tag f m) = 'runReaderT' tag m . f@
7375local
74− :: proxy tag
76+ :: Proxy# tag
7577 -> (r -> r)
7678 -- ^ The function to modify the environment.
7779 -> ReaderT tag r m a