<!-- λ Λ ∀ ≡ α β γ ρ ω Ω ○ μ η δ ζ ξ ⋆ ★ • ∙ ● 𝟎 𝟏 𝟐 𝟘 𝟙 𝟚 𝟬 𝟭 𝟮 ¢ ⇧ -->
+[[!toc levels=2]]
+
The Reader Monad
================
Then we lift the entire computation into the monad by applying ⇧ to
the integers, and by applying `map1` to the operators:
+<pre>
\tree ((((map2 +) (⇧1)) (((map2 *) (((map2 /) (⇧6)) (⇧0))) (⇧4))))
___________________
___|____ ⇧0
| |
map2 / ⇧6
+</pre>
With these adjustments, the faulty computation now completes smoothly:
1. Reduce head ((map2 +) -->
-The Reader Monad
-================
-
-The goal for this part is to introduce the Reader Monad, and present
-two linguistics applications: binding and intensionality. Along the
-way, we'll continue to think through issues related to order, and a
-related notion of flow of information.
-
-At this point, we've seen monads in general, and three examples of
-monads: the identity monad (invisible boxes), the Maybe monad (option
-types), and the List monad.
-
-We've also seen an application of the Maybe monad to safe division.
-The starting point was to allow the division function to return an int
-option instead of an int. If we divide 6 by 2, we get the answer Just
-3. But if we divide 6 by 0, we get the answer Nothing.
-
-The next step was to adjust the other arithmetic functions to know how
-to handle receiving Nothing instead of a (boxed) integer. This meant
-changing the type of their input from ints to int options. But we
-didn't need to do this piecemeal; rather, we could "lift" the ordinary
-arithmetic operations into the monad using the various tools provided
-by the monad.
-
-So let's see how this works in terms of a specific computation.
-
+%%%
<pre>
\tree ((((+) (1)) (((*) (((/) (6)) (2))) (4))))
Then we lift the entire computation into the monad by applying ⇧ to
the integers, and by applying `map1` to the operators:
+<pre>
\tree ((((map2 +) (⇧1)) (((map2 *) (((map2 /) (⇧6)) (⇧0))) (⇧4))))
___________________
___|____ ⇧0
| |
map2 / ⇧6
+</pre>
With these adjustments, the faulty computation now completes smoothly: