File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,14 +69,38 @@ import Data.Monoid
6969-- class MonadReader
7070-- asks for the internal (non-mutable) state.
7171
72- -- | See examples in "Control.Monad.Reader".
72+ -- | Monads with a notion of readable environment.
73+ --
74+ -- See examples in "Control.Monad.Reader".
7375-- Note, the partially applied function type @(->) r@ is a simple reader monad.
7476-- See the @instance@ declaration below.
77+ --
78+ -- === Laws
79+ --
80+ -- @
81+ -- m '<*>' 'ask' = 'ask' 'Control.Applicative.<**>' m
82+ --
83+ -- 'ask' '>>' 'pure' x = 'pure' x
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'.
7599class Monad m => MonadReader r m | m -> r where
76100#if __GLASGOW_HASKELL__ >= 707
77101 {-# MINIMAL (ask | reader), local #-}
78102#endif
79- -- | Retrieves the monad environment.
103+ -- | Retrieves the environment.
80104 ask :: m r
81105 ask = reader id
82106
You can’t perform that action at this time.
0 commit comments