Skip to content

Commit c026914

Browse files
author
Gregory Cox
committed
Change <a name...> anchors to id attributes on h2 tags
1 parent 03982fc commit c026914

14 files changed

+92
-92
lines changed

docs/a-fistful-of-monads.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ <h1>A Fistful of Monads</h1>
165165
three.
166166
</p>
167167

168-
<a name="getting-our-feet-wet-with-maybe"></a>
169-
<h2>Getting our feet wet with Maybe</h2>
168+
169+
<h2 id="getting-our-feet-wet-with-maybe">Getting our feet wet with Maybe</h2>
170170

171171
<img src="assets/images/a-fistful-of-monads/buddha.png" alt="monads, grasshoppa" class="left" width="302" height="387">
172172

@@ -370,8 +370,8 @@ <h2>Getting our feet wet with Maybe</h2>
370370
let’s check out the type class that belongs to monads.
371371
</p>
372372

373-
<a name="the-monad-type-class"></a>
374-
<h2>The Monad type class</h2>
373+
374+
<h2 id="the-monad-type-class">The Monad type class</h2>
375375

376376
<p>
377377
Just like functors have the <span class="fixed">Functor</span> type class and applicative
@@ -512,8 +512,8 @@ <h2>The Monad type class</h2>
512512
the result of using <span class="fixed">&gt;&gt;=</span> will be <span class="fixed">Nothing</span> as well.
513513
</p>
514514

515-
<a name="walk-the-line"></a>
516-
<h2>Walk the line</h2>
515+
516+
<h2 id="walk-the-line">Walk the line</h2>
517517

518518
<img src="assets/images/a-fistful-of-monads/pierre.png" alt="pierre" class="left" width="374" height="405">
519519

@@ -973,8 +973,8 @@ <h2>Walk the line</h2>
973973
possibility of failure was always taken into account.
974974
</p>
975975

976-
<a name="do-notation"></a>
977-
<h2>do notation</h2>
976+
977+
<h2 id="do-notation">do notation</h2>
978978

979979
<p>
980980
Monads in Haskell are so useful that they got their own special syntax called
@@ -1327,8 +1327,8 @@ <h2>do notation</h2>
13271327
monad instead of causing a program-wide failure, which is pretty neat.
13281328
</p>
13291329

1330-
<a name="the-list-monad"></a>
1331-
<h2>The list monad</h2>
1330+
1331+
<h2 id="the-list-monad">The list monad</h2>
13321332
<img src="assets/images/a-fistful-of-monads/deadcat.png" alt="dead cat" class="left" width="235" height="230">
13331333
<p>
13341334
So far, we’ve seen how <span class="fixed">Maybe</span> values can be viewed as
@@ -1839,8 +1839,8 @@ <h3>A knight’s quest</h3>
18391839
instead of that number being hardcoded like it is now.
18401840
</p>
18411841

1842-
<a name="monad-laws"></a>
1843-
<h2>Monad laws</h2>
1842+
1843+
<h2 id="monad-laws">Monad laws</h2>
18441844

18451845
<img src="assets/images/a-fistful-of-monads/judgedog.png" alt="the court finds you guilty of peeing all over
18461846
everything" class="right" width="343" height="170">

docs/for-a-few-monads-more.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ <h1>For a Few Monads More</h1>
6767
<span class="fixed">mtl</span>, followed by a version number.
6868
</p>
6969

70-
<a name="writer"></a>
71-
<h2>Writer? I hardly know her!</h2>
70+
71+
<h2 id="writer">Writer? I hardly know her!</h2>
7272

7373
<p>
7474
We’ve loaded our gun with the <span class="fixed">Maybe</span> monad, the list
@@ -973,8 +973,8 @@ <h3>Comparing Performance</h3>
973973
Enjoy!
974974
</p>
975975

976-
<a name="reader"></a>
977-
<h2>Reader? Ugh, not this joke again.</h2>
976+
977+
<h2 id="reader">Reader? Ugh, not this joke again.</h2>
978978

979979
<img src="assets/images/for-a-few-monads-more/revolver.png" alt="bang youre dead" class="left" width="280" height="106">
980980

@@ -1134,8 +1134,8 @@ <h2>Reader? Ugh, not this joke again.</h2>
11341134
implementation will make sure that it all works out.
11351135
</p>
11361136

1137-
<a name="state"></a>
1138-
<h2>Tasteful stateful computations</h2>
1137+
1138+
<h2 id="state">Tasteful stateful computations</h2>
11391139
<img src="assets/images/for-a-few-monads-more/texas.png" alt="don’t jest with texas" class="left" width="244" height="230">
11401140

11411141
<p>
@@ -1645,8 +1645,8 @@ <h3>Randomness and the state monad</h3>
16451645
steps just became much less of a hassle!
16461646
</p>
16471647

1648-
<a name="error"></a>
1649-
<h2>Error error on the wall</h2>
1648+
1649+
<h2 id="error">Error error on the wall</h2>
16501650

16511651
<p>
16521652
We know by now that <span class="fixed">Maybe</span> is used to add a
@@ -1806,8 +1806,8 @@ <h2>Error error on the wall</h2>
18061806
the pole when he fell.
18071807
</p>
18081808

1809-
<a name="useful-monadic-functions"></a>
1810-
<h2>Some useful monadic functions</h2>
1809+
1810+
<h2 id="useful-monadic-functions">Some useful monadic functions</h2>
18111811

18121812

18131813
<p>
@@ -2769,8 +2769,8 @@ <h3>Composing monadic functions</h3>
27692769
canReachIn x start end = end `elem` inMany x start
27702770
</pre>
27712771

2772-
<a name="making-monads"></a>
2773-
<h2>Making monads</h2>
2772+
2773+
<h2 id="making-monads">Making monads</h2>
27742774
<img src="assets/images/for-a-few-monads-more/spearhead.png" alt="kewl" class="center" width="780" height="244">
27752775

27762776
<p>

docs/functionally-solving-problems.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</div>
3434
<h1>Functionally Solving Problems</h1>
3535
<p>In this chapter, we’ll take a look at a few interesting problems and how to think functionally to solve them as elegantly as possible. We probably won’t be introducing any new concepts, we’ll just be flexing our newly acquired Haskell muscles and practicing our coding skills. Each section will present a different problem. First we’ll describe the problem, then we’ll try and find out what the best (or least worst) way of solving it is.</p>
36-
<a name="reverse-polish-notation-calculator"></a><h2>Reverse Polish notation calculator</h2>
36+
<h2 id="reverse-polish-notation-calculator">Reverse Polish notation calculator</h2>
3737
<p>Usually when we write mathematical expressions in school, we write them in an infix manner. For instance, we write <span class="fixed">10 - (4 + 3) * 2</span>. <span class="fixed">+</span>, <span class="fixed">*</span> and <span class="fixed">-</span> are infix operators, just like the infix functions we met in Haskell (<span class="fixed">+</span>, <span class="fixed">`elem`</span>, etc.). This makes it handy because we, as humans, can parse it easily in our minds by looking at such an expression. The downside to it is that we have to use parentheses to denote precedence.</p>
3838
<p><a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse Polish notation</a> is another way of writing down mathematical expressions. Initially it looks a bit weird, but it’s actually pretty easy to understand and use because there’s no need for parentheses and it’s very easy to punch into a calculator. While most modern calculators use infix notation, some people still swear by RPN calculators. This is what the previous infix expression looks like in RPN: <span class="fixed">10 4 3 + 2 * -</span>. How do we calculate what the result of that is? Well, think of a stack. You go over the expression from left to right. Every time a number is encountered, push it on to the stack. When we encounter an operator, take the two numbers that are on top of the stack (we also say that we <i>pop</i> them), use the operator and those two and then push the resulting number back onto the stack. When you reach the end of the expression, you should be left with a single number if the expression was well-formed and that number represents the result.</p>
3939
<img src="http://s3.amazonaws.com/lyah/rpn.png" alt="this expression" class="center" width="626" height="224">
@@ -126,7 +126,7 @@ <h1>Functionally Solving Problems</h1>
126126
</pre>
127127
<p>I think that making a function that can calculate arbitrary floating point RPN expressions and has the option to be easily extended in 10 lines is pretty awesome.</p>
128128
<p>One thing to note about this function is that it’s not really fault tolerant. When given input that doesn’t make sense, it will just crash everything. We’ll make a fault tolerant version of this with a type declaration of <span class="fixed">solveRPN :: String -&gt; Maybe Float</span> once we get to know monads (they’re not scary, trust me!). We could make one right now, but it would be a bit tedious because it would involve a lot of checking for <span class="fixed">Nothing</span> on every step. If you’re feeling up to the challenge though, you can go ahead and try it! Hint: you can use <span class="fixed">reads</span> to see if a read was successful or not. </p>
129-
<a name="heathrow-to-london"></a><h2>Heathrow to London</h2>
129+
<h2 id="heathrow-to-london">Heathrow to London</h2>
130130
<p>Our next problem is this: your plane has just landed in England and you rent a car. You have a meeting really soon and you have to get from Heathrow Airport to London as fast as you can (but safely!).</p>
131131
<p>There are two main roads going from Heathrow to London and there’s a number of regional roads crossing them. It takes you a fixed amount of time to travel from one crossroads to another. It’s up to you to find the optimal path to take so that you get to London as fast as you can! You start on the left side and can either cross to the other main road or go forward.</p>
132132
<img src="assets/images/functionally-solving-problems/roads.png" alt="Heathrow - London" class="center" width="780" height="237">

docs/functors-applicative-functors-and-monoids.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<h1>Functors, Applicative Functors and Monoids</h1>
3535
<p>Haskell’s combination of purity, higher order functions, parameterized algebraic data types, and typeclasses allows us to implement polymorphism on a much higher level than possible in other languages. We don’t have to think about types belonging to a big hierarchy of types. Instead, we think about what the types can act like and then connect them with the appropriate typeclasses. An <span class="fixed">Int</span> can act like a lot of things. It can act like an equatable thing, like an ordered thing, like an enumerable thing, etc.</p>
3636
<p>Typeclasses are open, which means that we can define our own data type, think about what it can act like and connect it with the typeclasses that define its behaviors. Because of that and because of Haskell’s great type system that allows us to know a lot about a function just by knowing its type declaration, we can define typeclasses that define behavior that’s very general and abstract. We’ve met typeclasses that define operations for seeing if two things are equal or comparing two things by some ordering. Those are very abstract and elegant behaviors, but we just don’t think of them as anything very special because we’ve been dealing with them for most of our lives. We recently met functors, which are basically things that can be mapped over. That’s an example of a useful and yet still pretty abstract property that typeclasses can describe. In this chapter, we’ll take a closer look at functors, along with slightly stronger and more useful versions of functors called applicative functors. We’ll also take a look at monoids, which are sort of like socks.</p>
37-
<a name="functors-redux"></a><h2>Functors redux</h2>
37+
<h2 id="functors-redux">Functors redux</h2>
3838
<img src="assets/images/functors-applicative-functors-and-monoids/frogtor.png" alt="frogs dont even need money" class="right" width="369" height="243">
3939
<p>We’ve already talked about functors in <a href="making-our-own-types-and-typeclasses.html#the-functor-typeclass">their own little section</a>. If you haven’t read it yet, you should probably give it a glance right now, or maybe later when you have more time. Or you can just pretend you read it.</p>
4040
<p>Still, here’s a quick refresher: Functors are things that can be mapped over, like lists, <span class="fixed">Maybe</span>s, trees, and such. In Haskell, they’re described by the typeclass <span class="fixed">Functor</span>, which has only one typeclass method, namely <span class="fixed">fmap</span>, which has a type of <span class="fixed">fmap :: (a -&gt; b) -&gt; f a -&gt; f b</span>. It says: give me a function that takes an <span class="fixed">a</span> and returns a <span class="fixed">b</span> and a box with an <span class="fixed">a</span> (or several of them) inside it and I’ll give you a box with a <span class="fixed">b</span> (or several of them) inside it. It kind of applies the function to the element inside the box.</p>
@@ -217,7 +217,7 @@ <h1>Functors, Applicative Functors and Monoids</h1>
217217
<p>All the <span class="fixed">Functor</span> instances in the standard library obey these laws, but you can check for yourself if you don’t believe me. And the next time you make a type an instance of <span class="fixed">Functor</span>, take a minute to make sure that it obeys the functor laws. Once you’ve dealt with enough functors, you kind of intuitively see the properties and behaviors that they have in common and it’s not hard to intuitively see if a type obeys the functor laws. But even without the intuition, you can always just go over the implementation line by line and see if the laws hold or try to find a counter-example.</p>
218218
<p>We can also look at functors as things that output values in a context. For instance, <span class="fixed">Just 3</span> outputs the value <span class="fixed">3</span> in the context that it might or not output any values at all. <span class="fixed">[1,2,3]</span> outputs three values—<span class="fixed">1</span>, <span class="fixed">2</span>, and <span class="fixed">3</span>, the context is that there may be multiple values or no values. The function <span class="fixed">(+3)</span> will output a value, depending on which parameter it is given.</p>
219219
<p>If you think of functors as things that output values, you can think of mapping over functors as attaching a transformation to the output of the functor that changes the value. When we do <span class="fixed">fmap (+3) [1,2,3]</span>, we attach the transformation <span class="fixed">(+3)</span> to the output of <span class="fixed">[1,2,3]</span>, so whenever we look at a number that the list outputs, <span class="fixed">(+3)</span> will be applied to it. Another example is mapping over functions. When we do <span class="fixed">fmap (+3) (*3)</span>, we attach the transformation <span class="fixed">(+3)</span> to the eventual output of <span class="fixed">(*3)</span>. Looking at it this way gives us some intuition as to why using <span class="fixed">fmap</span> on functions is just composition (<span class="fixed">fmap (+3) (*3)</span> equals <span class="fixed">(+3) . (*3)</span>, which equals <span class="fixed">\x -&gt; ((x*3)+3)</span>), because we take a function like <span class="fixed">(*3)</span> then we attach the transformation <span class="fixed">(+3)</span> to its output. The result is still a function, only when we give it a number, it will be multiplied by three and then it will go through the attached transformation where it will be added to three. This is what happens with composition.</p>
220-
<a name="applicative-functors"></a><h2>Applicative functors</h2>
220+
<h2 id="applicative-functors">Applicative functors</h2>
221221
<img src="assets/images/functors-applicative-functors-and-monoids/present.png" class="right" width="302" height="284" alt="disregard this analogy">
222222
<p>In this section, we’ll take a look at applicative functors, which are beefed up functors, represented in Haskell by the <span class="fixed">Applicative</span> typeclass, found in the <span class="fixed">Control.Applicative</span> module.</p>
223223
<p>As you know, functions in Haskell are curried by default, which means that a function that seems to take several parameters actually takes just one parameter and returns a function that takes the next parameter and so on. If a function is of type <span class="fixed">a -&gt; b -&gt; c</span>, we usually say that it takes two parameters and returns a <span class="fixed">c</span>, but actually it takes an <span class="fixed">a</span> and returns a function <span class="fixed">b -&gt; c</span>. That’s why we can call a function as <span class="fixed">f x y</span> or as <span class="fixed">(f x) y</span>. This mechanism is what enables us to partially apply functions by just calling them with too few parameters, which results in functions that we can then pass on to other functions.</p>
@@ -554,7 +554,7 @@ <h1>Functors, Applicative Functors and Monoids</h1>
554554
</ul>
555555
<p>We won’t go over them in detail right now because that would take up a lot of pages and it would probably be kind of boring, but if you’re up to the task, you can take a closer look at them and see if they hold for some of the instances.</p>
556556
<p>In conclusion, applicative functors aren’t just interesting, they’re also useful, because they allow us to combine different computations, such as I/O computations, non-deterministic computations, computations that might have failed, etc. by using the applicative style. Just by using <span class="fixed">&lt;$&gt;</span> and <span class="fixed">&lt;*&gt;</span> we can use normal functions to uniformly operate on any number of applicative functors and take advantage of the semantics of each one.</p>
557-
<a name="the-newtype-keyword"></a><h2>The newtype keyword</h2>
557+
<h2 id="the-newtype-keyword">The newtype keyword</h2>
558558

559559
<img src="assets/images/functors-applicative-functors-and-monoids/maoi.png" alt="why_ so serious?" class="left" width="107" height="202">
560560

@@ -1062,7 +1062,7 @@ <h3><span class="fixed">type</span> vs. <span class="fixed">newtype</span> vs.
10621062
keyword.
10631063
</p>
10641064

1065-
<a name="monoids"></a><h2>Monoids</h2>
1065+
<h2 id="monoids">Monoids</h2>
10661066

10671067
<img src="assets/images/functors-applicative-functors-and-monoids/pirateship.png" alt="wow this is pretty much the gayest pirate ship
10681068
ever" class="right" width="460" height="417">

0 commit comments

Comments
 (0)