File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -69,14 +69,38 @@ import Data.Monoid
69
69
-- class MonadReader
70
70
-- asks for the internal (non-mutable) state.
71
71
72
- -- | See examples in "Control.Monad.Reader".
72
+ -- | Monads with a notion of readable environment.
73
+ --
74
+ -- See examples in "Control.Monad.Reader".
73
75
-- Note, the partially applied function type @(->) r@ is a simple reader monad.
74
76
-- See the @instance@ declaration below.
77
+ --
78
+ -- === Laws
79
+ --
80
+ -- @
81
+ -- m '<*>' 'ask' = 'ask' 'Control.Applicative.<**>' m
82
+ --
83
+ -- 'ask' '>>' m = m
84
+ -- 'ask' '>>=' \\s1 -> 'ask' '>>=' \\s2 -> k s1 s2 = 'ask' '>>=' \\s -> k s s
85
+ --
86
+ -- 'local' f 'ask' = f '<$>' 'ask'
87
+ -- 'local' g '.' 'local' f = 'local' (g '.' f)
88
+ --
89
+ -- -- 'local' is a monad morphism from 'm' to 'm'
90
+ -- 'local' f ('pure' x) = 'pure' x
91
+ -- 'local' f (a '>>=' k) = 'local' f a '>>=' \\x -> 'local' f (k x)
92
+ --
93
+ -- 'ask' = 'reader' 'id'
94
+ -- @
95
+ --
96
+ -- An equivalent requirement to the first two laws is that 'reader' (as given
97
+ -- by the default implementation) must be a monad morphism from @'Reader' r@
98
+ -- to 'm'.
75
99
class Monad m => MonadReader r m | m -> r where
76
100
#if __GLASGOW_HASKELL__ >= 707
77
101
{-# MINIMAL (ask | reader), local #-}
78
102
#endif
79
- -- | Retrieves the monad environment.
103
+ -- | Retrieves the environment.
80
104
ask :: m r
81
105
ask = reader id
82
106
You can’t perform that action at this time.
0 commit comments