on master help sign in
Proxy-hash for MonadWriter
7a9ddd0Index Int
src/Control/Monad/Ether/Implicit/Writer.hs+13−12
@@ -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.Writer".
5-- | See "Control.Monad.Ether.Writer".
5
6
@@ -24,7 +25,7 @@ module Control.Monad.Ether.Implicit.Writer
24 , execWriterT
25 , execWriterT
25 ) where
26 ) where
26
27
27−import Data.Proxy
28+import GHC.Prim (Proxy#, proxy#)
28import qualified Control.Monad.Ether.Writer as Explicit
29import qualified Control.Monad.Ether.Writer as Explicit
29
30
30-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
31-- | See 'Control.Monad.Ether.Writer.MonadWriter'.
@@ -32,50 +33,50 @@ type MonadWriter w = Explicit.MonadWriter w w
32
33
33-- | See 'Control.Monad.Ether.Writer.writer'.
34-- | See 'Control.Monad.Ether.Writer.writer'.
34writer :: forall w m a . MonadWriter w m => (a, w) -> m a
35writer :: forall w m a . MonadWriter w m => (a, w) -> m a
35−writer = Explicit.writer (Proxy :: Proxy w)
36+writer = Explicit.writer (proxy# :: Proxy# w)
36
37
37-- | See 'Control.Monad.Ether.Writer.tell'.
38-- | See 'Control.Monad.Ether.Writer.tell'.
38tell :: forall w m . MonadWriter w m => w -> m ()
39tell :: forall w m . MonadWriter w m => w -> m ()
39−tell = Explicit.tell (Proxy :: Proxy w)
40+tell = Explicit.tell (proxy# :: Proxy# w)
40
41
41-- | See 'Control.Monad.Ether.Writer.listen'.
42-- | See 'Control.Monad.Ether.Writer.listen'.
42listen :: forall w m a . MonadWriter w m => m a -> m (a, w)
43listen :: forall w m a . MonadWriter w m => m a -> m (a, w)
43−listen = Explicit.listen (Proxy :: Proxy w)
44+listen = Explicit.listen (proxy# :: Proxy# w)
44
45
45-- | See 'Control.Monad.Ether.Writer.pass'.
46-- | See 'Control.Monad.Ether.Writer.pass'.
46pass :: forall w m a . MonadWriter w m => m (a, w -> w) -> m a
47pass :: forall w m a . MonadWriter w m => m (a, w -> w) -> m a
47−pass = Explicit.pass (Proxy :: Proxy w)
48+pass = Explicit.pass (proxy# :: Proxy# w)
48
49
49-- | See 'Control.Monad.Ether.Writer.listens'.
50-- | See 'Control.Monad.Ether.Writer.listens'.
50listens :: forall w m a b . MonadWriter w m => (w -> b) -> m a -> m (a, b)
51listens :: forall w m a b . MonadWriter w m => (w -> b) -> m a -> m (a, b)
51−listens = Explicit.listens (Proxy :: Proxy w)
52+listens = Explicit.listens (proxy# :: Proxy# w)
52
53
53-- | See 'Control.Monad.Ether.Writer.censor'.
54-- | See 'Control.Monad.Ether.Writer.censor'.
54censor :: forall w m a . MonadWriter w m => (w -> w) -> m a -> m a
55censor :: forall w m a . MonadWriter w m => (w -> w) -> m a -> m a
55−censor = Explicit.censor (Proxy :: Proxy w)
56+censor = Explicit.censor (proxy# :: Proxy# w)
56
57
57-- | See 'Control.Monad.Ether.Writer.Writer'.
58-- | See 'Control.Monad.Ether.Writer.Writer'.
58type Writer w = Explicit.Writer w w
59type Writer w = Explicit.Writer w w
59
60
60-- | See 'Control.Monad.Ether.Writer.runWriter'.
61-- | See 'Control.Monad.Ether.Writer.runWriter'.
61runWriter :: Writer w a -> (a, w)
62runWriter :: Writer w a -> (a, w)
62−runWriter = Explicit.runWriter Proxy
63+runWriter = Explicit.runWriter proxy#
63
64
64-- | See 'Control.Monad.Ether.Writer.execWriter'.
65-- | See 'Control.Monad.Ether.Writer.execWriter'.
65execWriter :: Writer w a -> w
66execWriter :: Writer w a -> w
66−execWriter = Explicit.execWriter Proxy
67+execWriter = Explicit.execWriter proxy#
67
68
68-- | See 'Control.Monad.Ether.Writer.WriterT'.
69-- | See 'Control.Monad.Ether.Writer.WriterT'.
69type WriterT w = Explicit.WriterT w w
70type WriterT w = Explicit.WriterT w w
70
71
71-- | See 'Control.Monad.Ether.Writer.writerT'.
72-- | See 'Control.Monad.Ether.Writer.writerT'.
72writerT :: m (a, w) -> WriterT w m a
73writerT :: m (a, w) -> WriterT w m a
73−writerT = Explicit.writerT Proxy
74+writerT = Explicit.writerT proxy#
74
75
75-- | See 'Control.Monad.Ether.Writer.runWriterT'.
76-- | See 'Control.Monad.Ether.Writer.runWriterT'.
76runWriterT :: WriterT w m a -> m (a, w)
77runWriterT :: WriterT w m a -> m (a, w)
77−runWriterT = Explicit.runWriterT Proxy
78+runWriterT = Explicit.runWriterT proxy#
78
79
79-- | See 'Control.Monad.Ether.Writer.execWriterT'.
80-- | See 'Control.Monad.Ether.Writer.execWriterT'.
80execWriterT :: Monad m => WriterT w m a -> m w
81execWriterT :: Monad m => WriterT w m a -> m w
81−execWriterT = Explicit.execWriterT Proxy
82+execWriterT = Explicit.execWriterT proxy#
src/Control/Monad/Ether/Writer/Class.hs+8−6
@@ -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.Writer.Class".
16-- | See "Control.Monad.Writer.Class".
16
17
@@ -24,6 +25,7 @@ module Control.Monad.Ether.Writer.Class
24import Data.Monoid
25import Data.Monoid
25#endif
26#endif
26
27
28+import GHC.Prim (Proxy#)
27import qualified Control.Monad.Trans.Ether.Writer as W
29import qualified Control.Monad.Trans.Ether.Writer as W
28import qualified Control.Monad.Trans.Lift.Listen as Lift
30import qualified Control.Monad.Trans.Lift.Listen as Lift
29import qualified Control.Monad.Trans.Lift.Pass as Lift
31import qualified Control.Monad.Trans.Lift.Pass as Lift
@@ -34,32 +36,32 @@ class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where
34 {-# MINIMAL (writer | tell), listen, pass #-}
36 {-# MINIMAL (writer | tell), listen, pass #-}
35
37
36 -- | Embed a simple writer action.
38 -- | Embed a simple writer action.
37− writer :: proxy tag -> (a, w) -> m a
39+ writer :: Proxy# tag -> (a, w) -> m a
38 writer t ~(a, w) = do
40 writer t ~(a, w) = do
39 tell t w
41 tell t w
40 return a
42 return a
41
43
42 -- | Append a value to the accumulator within the monad.
44 -- | Append a value to the accumulator within the monad.
43− tell :: proxy tag -> w -> m ()
45+ tell :: Proxy# tag -> w -> m ()
44 tell t w = writer t ((),w)
46 tell t w = writer t ((),w)
45
47
46 -- | Execute an action and add its accumulator
48 -- | Execute an action and add its accumulator
47 -- to the value of the computation.
49 -- to the value of the computation.
48− listen :: proxy tag -> m a -> m (a, w)
50+ listen :: Proxy# tag -> m a -> m (a, w)
49
51
50 -- | Execute an action which returns a value and a function,
52 -- | Execute an action which returns a value and a function,
51 -- and return the value, applying the function to the accumulator.
53 -- and return the value, applying the function to the accumulator.
52− pass :: proxy tag -> m (a, w -> w) -> m a
54+ pass :: Proxy# tag -> m (a, w -> w) -> m a
53
55
54-- | Execute an action and add the result of applying the given function to
56-- | Execute an action and add the result of applying the given function to
55-- its accumulator to the value of the computation.
57-- its accumulator to the value of the computation.
56−listens :: MonadWriter tag w m => proxy tag -> (w -> b) -> m a -> m (a, b)
58+listens :: MonadWriter tag w m => Proxy# tag -> (w -> b) -> m a -> m (a, b)
57listens t f m = do
59listens t f m = do
58 ~(a, w) <- listen t m
60 ~(a, w) <- listen t m
59 return (a, f w)
61 return (a, f w)
60
62
61-- | Execute an action and apply a function to its accumulator.
63-- | Execute an action and apply a function to its accumulator.
62−censor :: MonadWriter tag w m => proxy tag -> (w -> w) -> m a -> m a
64+censor :: MonadWriter tag w m => Proxy# tag -> (w -> w) -> m a -> m a
63censor t f m = pass t $ do
65censor t f m = pass t $ do
64 a <- m
66 a <- m
65 return (a, f)
67 return (a, f)
src/Control/Monad/Trans/Ether/Dispatch.hs+8−8
@@ -180,10 +180,10 @@ instance MonadExcept tag e m
180
180
181instance MonadWriter tag w m
181instance MonadWriter tag w m
182 => Class.MonadWriter w (DispatchTagAttachT tag m) where
182 => Class.MonadWriter w (DispatchTagAttachT tag m) where
183− writer = let t = Proxy :: Proxy tag in Lift.lift . writer t
183+ writer = let t = proxy# :: Proxy# tag in Lift.lift . writer t
184− tell = let t = Proxy :: Proxy tag in Lift.lift . tell t
184+ tell = let t = proxy# :: Proxy# tag in Lift.lift . tell t
185− listen = let t = Proxy :: Proxy tag in Lift.liftListen (listen t)
185+ listen = let t = proxy# :: Proxy# tag in Lift.liftListen (listen t)
186− pass = let t = Proxy :: Proxy tag in Lift.liftPass (pass t)
186+ pass = let t = proxy# :: Proxy# tag in Lift.liftPass (pass t)
187
187
188
188
189-- TagReplace instances
189-- TagReplace instances
@@ -205,7 +205,7 @@ instance MonadExcept tNew e m
205
205
206instance MonadWriter tNew w m
206instance MonadWriter tNew w m
207 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
207 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
208− writer _ = let t = Proxy :: Proxy tNew in Lift.lift . writer t
208+ writer _ = let t = proxy# :: Proxy# tNew in Lift.lift . writer t
209− tell _ = let t = Proxy :: Proxy tNew in Lift.lift . tell t
209+ tell _ = let t = proxy# :: Proxy# tNew in Lift.lift . tell t
210− listen _ = let t = Proxy :: Proxy tNew in Lift.liftListen (listen t)
210+ listen _ = let t = proxy# :: Proxy# tNew in Lift.liftListen (listen t)
211− pass _ = let t = Proxy :: Proxy tNew in Lift.liftPass (pass t)
211+ pass _ = let t = proxy# :: Proxy# tNew in Lift.liftPass (pass t)
src/Control/Monad/Trans/Ether/Writer.hs+11−9
@@ -7,6 +7,7 @@
7{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE DataKinds #-}
8{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10+{-# LANGUAGE MagicHash #-}
10
11
11-- | See "Control.Monad.Trans.Writer".
12-- | See "Control.Monad.Trans.Writer".
12
13
@@ -32,6 +33,7 @@ module Control.Monad.Trans.Ether.Writer
32import Data.Monoid
33import Data.Monoid
33#endif
34#endif
34
35
36+import GHC.Prim (Proxy#)
35import Data.Functor.Identity (Identity(..))
37import Data.Functor.Identity (Identity(..))
36import qualified Control.Monad.Trans.Writer.Lazy as Trans
38import qualified Control.Monad.Trans.Writer.Lazy as Trans
37import Control.Monad.Trans.Ether.Tagged
39import Control.Monad.Trans.Ether.Tagged
@@ -51,36 +53,36 @@ type Writer tag w = WriterT tag w Identity
51type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
53type WriterT tag w = TaggedTrans tag (Trans.WriterT w)
52
54
53-- | Constructor for computations in the writer monad transformer.
55-- | Constructor for computations in the writer monad transformer.
54−writerT :: proxy tag -> m (a, w) -> WriterT tag w m a
56+writerT :: Proxy# tag -> m (a, w) -> WriterT tag w m a
55writerT _ = pack . Trans.WriterT
57writerT _ = pack . Trans.WriterT
56
58
57-- | Constructor for computations in the writer monad
59-- | Constructor for computations in the writer monad
58-- (the inverse of 'runWriter').
60-- (the inverse of 'runWriter').
59−writer :: Monad m => proxy tag -> (a, w) -> WriterT tag w m a
61+writer :: Monad m => Proxy# tag -> (a, w) -> WriterT tag w m a
60writer _ = pack . Trans.writer
62writer _ = pack . Trans.writer
61
63
62-- | Runs a 'WriterT' and returns both the normal value
64-- | Runs a 'WriterT' and returns both the normal value
63-- and the final accumulator.
65-- and the final accumulator.
64−runWriterT :: proxy tag -> WriterT tag w m a -> m (a, w)
66+runWriterT :: Proxy# tag -> WriterT tag w m a -> m (a, w)
65runWriterT _ = Trans.runWriterT . unpack
67runWriterT _ = Trans.runWriterT . unpack
66
68
67-- | Runs a 'Writer' and returns both the normal value
69-- | Runs a 'Writer' and returns both the normal value
68-- and the final accumulator.
70-- and the final accumulator.
69−runWriter :: proxy tag -> Writer tag w a -> (a, w)
71+runWriter :: Proxy# tag -> Writer tag w a -> (a, w)
70runWriter _ = Trans.runWriter . unpack
72runWriter _ = Trans.runWriter . unpack
71
73
72-- | Runs a 'WriterT' and returns the final accumulator,
74-- | Runs a 'WriterT' and returns the final accumulator,
73-- discarding the normal value.
75-- discarding the normal value.
74−execWriterT :: Monad m => proxy tag -> WriterT tag w m a -> m w
76+execWriterT :: Monad m => Proxy# tag -> WriterT tag w m a -> m w
75execWriterT _ = Trans.execWriterT . unpack
77execWriterT _ = Trans.execWriterT . unpack
76
78
77-- | Runs a 'Writer' and returns the final accumulator,
79-- | Runs a 'Writer' and returns the final accumulator,
78-- discarding the normal value.
80-- discarding the normal value.
79−execWriter :: proxy tag -> Writer tag w a -> w
81+execWriter :: Proxy# tag -> Writer tag w a -> w
80execWriter _ = Trans.execWriter . unpack
82execWriter _ = Trans.execWriter . unpack
81
83
82-- | Appends a value to the accumulator within the monad.
84-- | Appends a value to the accumulator within the monad.
83−tell :: Monad m => proxy tag -> w -> WriterT tag w m ()
85+tell :: Monad m => Proxy# tag -> w -> WriterT tag w m ()
84tell t w = writer t ((), w)
86tell t w = writer t ((), w)
85
87
86-- | Executes an action and adds its accumulator to the value of the computation.
88-- | Executes an action and adds its accumulator to the value of the computation.
@@ -90,7 +92,7 @@ listen
90#else
92#else
91 :: Monad m
93 :: Monad m
92#endif
94#endif
93− => proxy tag -> WriterT tag w m a -> WriterT tag w m (a, w)
95+ => Proxy# tag -> WriterT tag w m a -> WriterT tag w m (a, w)
94listen _ = pack . Trans.listen . unpack
96listen _ = pack . Trans.listen . unpack
95
97
96-- | Executes an action which returns a value and a function, and returns the
98-- | Executes an action which returns a value and a function, and returns the
@@ -101,5 +103,5 @@ pass
101#else
103#else
102 :: Monad m
104 :: Monad m
103#endif
105#endif
104− => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
106+ => Proxy# tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
105pass _ = pack . Trans.pass . unpack
107pass _ = pack . Trans.pass . unpack