|
31 | 31 | </li> |
32 | 32 | </ul> |
33 | 33 | </div> |
34 | | - <h1>For a Few Monads More</h1> |
| 34 | + <h1 id="for-a-few-monads-more">For a Few Monads More</h1> |
35 | 35 |
|
36 | 36 | <img src="assets/images/for-a-few-monads-more/clint.png" alt="there are two kinds of people in the world, my friend. those who learn them a haskell and those who have the job of coding java" class="right" width="189" height="400"> |
37 | 37 |
|
@@ -217,7 +217,7 @@ <h2 id="writer">Writer? I hardly know her!</h2> |
217 | 217 | appending the logs. |
218 | 218 | </p> |
219 | 219 |
|
220 | | -<h3>Monoids to the rescue</h3> |
| 220 | +<h3 id="monoids-to-the-rescue">Monoids to the rescue</h3> |
221 | 221 |
|
222 | 222 | <div class="hintbox"> |
223 | 223 | Be sure you know what <a href="functors-applicative-functors-and-monoids.html#monoids">monoids</a> are at this point! Cheers. |
@@ -353,7 +353,7 @@ <h3>Monoids to the rescue</h3> |
353 | 353 | <span class="fixed">("beer", Sum 65)</span>. |
354 | 354 | </p> |
355 | 355 |
|
356 | | -<h3>The Writer type</h3> |
| 356 | +<h3 id="the-writer-type">The Writer type</h3> |
357 | 357 |
|
358 | 358 | <p> |
359 | 359 | Now that we’ve seen that a value with an attached monoid acts like a monadic |
@@ -455,7 +455,7 @@ <h3>The Writer type</h3> |
455 | 455 | <span class="fixed">do</span> notation, <span class="fixed">error</span> is called. |
456 | 456 | </p> |
457 | 457 |
|
458 | | -<h3>Using do notation with Writer</h3> |
| 458 | +<h3 id="using-do-notation-with-writer">Using do notation with Writer</h3> |
459 | 459 |
|
460 | 460 | <p> |
461 | 461 | Now that we have a <span class="fixed">Monad</span> instance, we’re free to use |
@@ -539,7 +539,7 @@ <h3>Using do notation with Writer</h3> |
539 | 539 | (15,["Got number: 3","Got number: 5","Gonna multiply these two"]) |
540 | 540 | </pre> |
541 | 541 |
|
542 | | -<h3>Adding logging to programs</h3> |
| 542 | +<h3 id="adding-logging-to-programs">Adding logging to programs</h3> |
543 | 543 |
|
544 | 544 | <p> |
545 | 545 | Euclid’s algorithm is an algorithm that takes two numbers and computes their |
@@ -677,7 +677,7 @@ <h3>Adding logging to programs</h3> |
677 | 677 | <span class="fixed">do</span> expressions if it increases readability). |
678 | 678 | </p> |
679 | 679 |
|
680 | | -<h3>Inefficient list construction</h3> |
| 680 | +<h3 id="inefficient-list-construction">Inefficient list construction</h3> |
681 | 681 |
|
682 | 682 | <p> |
683 | 683 | When using the <span class="fixed">Writer</span> monad, you have to be careful |
@@ -754,7 +754,7 @@ <h3>Inefficient list construction</h3> |
754 | 754 | the left instead of to the right. |
755 | 755 | </p> |
756 | 756 |
|
757 | | -<h3>Difference lists</h3> |
| 757 | +<h3 id="difference-lists">Difference lists</h3> |
758 | 758 |
|
759 | 759 | <img src="assets/images/for-a-few-monads-more/cactus.png" alt="cactuses" class="left" width="147" height="300"> |
760 | 760 |
|
@@ -897,7 +897,7 @@ <h3>Difference lists</h3> |
897 | 897 | finally print its entries to the screen. |
898 | 898 | </p> |
899 | 899 |
|
900 | | -<h3>Comparing Performance</h3> |
| 900 | +<h3 id="comparing-performance">Comparing Performance</h3> |
901 | 901 |
|
902 | 902 | <p> |
903 | 903 | To get a feel for just how much difference lists may improve your performance, |
@@ -1223,7 +1223,7 @@ <h2 id="state">Tasteful stateful computations</h2> |
1223 | 1223 | from getting a result we also get a new state. |
1224 | 1224 | </p> |
1225 | 1225 |
|
1226 | | -<h3>Stacks and stones</h3> |
| 1226 | +<h3 id="stacks-and-stones">Stacks and stones</h3> |
1227 | 1227 |
|
1228 | 1228 | <p> |
1229 | 1229 | Say we want to model operating a stack. You have a stack of things one on top |
@@ -1323,7 +1323,7 @@ <h3>Stacks and stones</h3> |
1323 | 1323 | the state manually. |
1324 | 1324 | </p> |
1325 | 1325 |
|
1326 | | -<h3>The State monad</h3> |
| 1326 | +<h3 id="the-state-monad">The State monad</h3> |
1327 | 1327 |
|
1328 | 1328 | <p> |
1329 | 1329 | The <span class="fixed">Control.Monad.State</span> module provides a |
@@ -1574,7 +1574,7 @@ <h3>The State monad</h3> |
1574 | 1574 | different monads. |
1575 | 1575 | </p> |
1576 | 1576 |
|
1577 | | -<h3>Randomness and the state monad</h3> |
| 1577 | +<h3 id="randomness-and-the-state-monad">Randomness and the state monad</h3> |
1578 | 1578 |
|
1579 | 1579 | <p> |
1580 | 1580 | At the beginning of this section, we saw how generating numbers can sometimes be |
@@ -1819,7 +1819,7 @@ <h2 id="useful-monadic-functions">Some useful monadic functions</h2> |
1819 | 1819 | Let’s see what they are then! |
1820 | 1820 | </p> |
1821 | 1821 |
|
1822 | | -<h3>liftM and friends</h3> |
| 1822 | +<h3 id="liftm-and-friends">liftM and friends</h3> |
1823 | 1823 |
|
1824 | 1824 | <img src="assets/images/for-a-few-monads-more/wolf.png" alt="im a cop too" class="right" width="394" height="222"> |
1825 | 1825 |
|
@@ -2044,7 +2044,7 @@ <h3>liftM and friends</h3> |
2044 | 2044 | and applicative functors use. |
2045 | 2045 | </p> |
2046 | 2046 |
|
2047 | | -<h3>The join function</h3> |
| 2047 | +<h3 id="the-join-function">The join function</h3> |
2048 | 2048 |
|
2049 | 2049 | <p> |
2050 | 2050 | Here’s some food for thought: if the result of one monadic value is another |
@@ -2210,7 +2210,7 @@ <h3>The join function</h3> |
2210 | 2210 | out how to implement <span class="fixed">>>=</span>. |
2211 | 2211 | </p> |
2212 | 2212 |
|
2213 | | -<h3>filterM</h3> |
| 2213 | +<h3 id="filterm">filterM</h3> |
2214 | 2214 |
|
2215 | 2215 | <p> |
2216 | 2216 | The <span class="fixed">filter</span> function is pretty much the bread of |
@@ -2383,7 +2383,7 @@ <h3>filterM</h3> |
2383 | 2383 | to be everything at once, it’s a bit easier. |
2384 | 2384 | </p> |
2385 | 2385 |
|
2386 | | -<h3>foldM</h3> |
| 2386 | +<h3 id="foldm">foldM</h3> |
2387 | 2387 |
|
2388 | 2388 | <p> |
2389 | 2389 | The monadic counterpart to <span class="fixed">foldl</span> is |
@@ -2466,7 +2466,7 @@ <h3>foldM</h3> |
2466 | 2466 | whatever you want as your fold goes along its way. |
2467 | 2467 | </p> |
2468 | 2468 |
|
2469 | | -<h3>Making a safe RPN calculator</h3> |
| 2469 | +<h3 id="making-a-safe-rpn-calculator">Making a safe RPN calculator</h3> |
2470 | 2470 |
|
2471 | 2471 | <img src="assets/images/for-a-few-monads-more/miner.png" alt="i’ve found yellow!" class="left" width="280" height="396"> |
2472 | 2472 |
|
@@ -2656,7 +2656,7 @@ <h3>Making a safe RPN calculator</h3> |
2656 | 2656 | returns a <span class="fixed">Nothing</span>. |
2657 | 2657 | </p> |
2658 | 2658 |
|
2659 | | -<h3>Composing monadic functions</h3> |
| 2659 | +<h3 id="composing-monadic-functions">Composing monadic functions</h3> |
2660 | 2660 |
|
2661 | 2661 | <p> |
2662 | 2662 | When we were learning about the monad laws, we said that the |
|
0 commit comments