Skip to content

Commit fc98cd1

Browse files
author
Gregory Cox
committed
Reflect typo fixes in learnyouahaskell#47 in markdown
1 parent 1bda6b2 commit fc98cd1

28 files changed

+298
-296
lines changed

markdown/generated_html/a-fistful-of-monads.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ <h2 id="the-monad-type-class">The Monad type class</h2>
272272
constraint in there along the lines of
273273
<code>class (Applicative m) = &gt; Monad m where</code> so that a type
274274
has to be an applicative functor first before it can be made a monad?
275-
Well, there should, but when Haskell was made, it hadn’t occured to
275+
Well, there should, but when Haskell was made, it hadn’t occurred to
276276
people that applicative functors are a good fit for Haskell so they
277277
weren’t in there. But rest assured, every monad is an applicative
278278
functor, even if the <code>Monad</code> class declaration doesn’t say

markdown/generated_html/for-a-few-monads-more.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ <h2 id="writer">Writer? I hardly know her!</h2>
7474
isBigGang x = x &gt; 9</code></pre>
7575
<p>Now, what if instead of just giving us a <code>True</code> or
7676
<code>False</code> value, we want it to also return a log string that
77-
says what it did? Well, we just make that string and return it along
78-
side our <code>Bool</code>:</p>
77+
says what it did? Well, we just make that string and return it alongside
78+
our <code>Bool</code>:</p>
7979
<pre class="haskell:hs"><code>isBigGang :: Int -&gt; (Bool, String)
8080
isBigGang x = (x &gt; 9, &quot;Compared gang size to 9.&quot;)</code></pre>
8181
<p>So now instead of just returning a <code>Bool</code>, we return a
@@ -376,8 +376,8 @@ <h3 id="adding-logging-to-programs">Adding logging to programs</h3>
376376
is, we just follow the algorithm outlined. Because 3 isn’t 0, we have to
377377
find the greatest common divisor of 3 and 2 (if we divide 8 by 3, the
378378
remainder is 2). Next, we find the greatest common divisor of 3 and 2. 2
379-
still isn’t 0, so now we have have 2 and 1. The second number isn’t 0,
380-
so we run the algorithm again for 1 and 0, as dividing 2 by 1 gives us a
379+
still isn’t 0, so now we have 2 and 1. The second number isn’t 0, so we
380+
run the algorithm again for 1 and 0, as dividing 2 by 1 gives us a
381381
remainder of 0. And finally, because the second number is now 0, the
382382
final result is 1. Let’s see if our code agrees:</p>
383383
<pre class="haskell:hs"><code>ghci&gt; gcd&#39; 8 3
@@ -795,7 +795,7 @@ <h3 id="stacks-and-stones">Stacks and stones</h3>
795795
or you can take stuff off the top of the stack. When you’re putting an
796796
item on top of the stack we say that you’re pushing it to the stack and
797797
when you’re taking stuff off the top we say that you’re popping it. If
798-
you want to something that’s at the bottom of the stack, you have to pop
798+
you want something that’s at the bottom of the stack, you have to pop
799799
everything that’s above it.</p>
800800
<p>We’ll use a list to represent our stack and the head of the list will
801801
be the top of the stack. To help us with our task, we’ll make two
@@ -1031,7 +1031,7 @@ <h3 id="randomness-and-the-state-monad">Randomness and the state
10311031
b &lt;- randomSt
10321032
c &lt;- randomSt
10331033
return (a,b,c)</code></pre>
1034-
<p><code>threeCoins</code> is now a stateful computations and after
1034+
<p><code>threeCoins</code> is now a stateful computation and after
10351035
taking an initial random generator, it passes it to the first
10361036
<code>randomSt</code>, which produces a number and a new generator,
10371037
which gets passed to the next one and so on. We use
@@ -1771,7 +1771,7 @@ <h2 id="making-monads">Making monads</h2>
17711771
while <code>5</code> and <code>9</code> will happen one time out of
17721772
four. Pretty neat.</p>
17731773
<p>We took lists and we added some extra context to them, so this
1774-
represents values withs contexts too. Before we go any further, let’s
1774+
represents values with contexts too. Before we go any further, let’s
17751775
wrap this into a <code>newtype</code> because something tells me we’ll
17761776
be making some instances.</p>
17771777
<pre class="haskell:hs"><code>import Data.Ratio

markdown/generated_html/functionally-solving-problems.html

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ <h1 id="functionally-solving-problems">Functionally Solving
3838
probably won’t be introducing any new concepts, we’ll just be flexing
3939
our newly acquired Haskell muscles and practicing our coding skills.
4040
Each section will present a different problem. First we’ll describe the
41-
problem, then we’ll try and find out what the best (or least worst) way
42-
of solving it is.</p>
41+
problem, then we’ll try and find out what the best (or least bad) way of
42+
solving it is.</p>
4343
<h2 id="reverse-polish-notation-calculator">Reverse Polish notation
4444
calculator</h2>
4545
<p>Usually when we write mathematical expressions in school, we write
@@ -225,7 +225,7 @@ <h2 id="reverse-polish-notation-calculator">Reverse Polish notation
225225
easily modified to support various other operators. They don’t even have
226226
to be binary operators. For instance, we can make an operator
227227
<code>"log"</code> that just pops one number off the stack and pushes
228-
back its logarithm. We can also make a ternary operators that pop three
228+
back its logarithm. We can also make ternary operators that pop three
229229
numbers off the stack and push back a result or operators like
230230
<code>"sum"</code> which pop off all the numbers and push back their
231231
sum.</p>
@@ -265,15 +265,16 @@ <h2 id="reverse-polish-notation-calculator">Reverse Polish notation
265265
<p>I think that making a function that can calculate arbitrary floating
266266
point RPN expressions and has the option to be easily extended in 10
267267
lines is pretty awesome.</p>
268-
<p>One thing to note about this function is that it’s not really fault
269-
tolerant. When given input that doesn’t make sense, it will just crash
270-
everything. We’ll make a fault tolerant version of this with a type
271-
declaration of <code>solveRPN :: String -&gt; Maybe Float</code> once we
272-
get to know monads (they’re not scary, trust me!). We could make one
273-
right now, but it would be a bit tedious because it would involve a lot
274-
of checking for <code>Nothing</code> on every step. If you’re feeling up
275-
to the challenge though, you can go ahead and try it! Hint: you can use
276-
<code>reads</code> to see if a read was successful or not.</p>
268+
<p>One thing to note about this function is that it’s not really
269+
fault-tolerant. When given input that doesn’t make sense, it will just
270+
crash everything. We’ll make a fault tolerant version of this with a
271+
type declaration of <code>solveRPN :: String -&gt; Maybe Float</code>
272+
once we get to know monads (they’re not scary, trust me!). We could make
273+
one right now, but it would be a bit tedious because it would involve a
274+
lot of checking for <code>Nothing</code> on every step. If you’re
275+
feeling up to the challenge though, you can go ahead and try it! Hint:
276+
you can use <code>reads</code> to see if a read was successful or
277+
not.</p>
277278
<h2 id="heathrow-to-london">Heathrow to London</h2>
278279
<p>Our next problem is this: your plane has just landed in England and
279280
you rent a car. You have a meeting really soon and you have to get from

markdown/generated_html/functors-applicative-functors-and-monoids.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ <h2 id="functors-redux">Functors redux</h2>
206206
<code>r -&gt; a</code> can be rewritten as <code>(-&gt;) r a</code>,
207207
much like we can write <code>2 + 3</code> as <code>(+) 2 3</code>. When
208208
we look at it as <code>(-&gt;) r a</code>, we can see
209-
<code>(-&gt;)</code> in a slighty different light, because we see that
209+
<code>(-&gt;)</code> in a slightly different light, because we see that
210210
it’s just a type constructor that takes two type parameters, just like
211211
<code>Either</code>. But remember, we said that a type constructor has
212212
to take exactly one type parameter so that it can be made an instance of
@@ -493,7 +493,7 @@ <h2 id="functors-redux">Functors redux</h2>
493493
<p>If we use the <code>CNothing</code> constructor, there are no fields,
494494
and if we use the <code>CJust</code> constructor, the first field is an
495495
integer and the second field can be any type. Let’s make this an
496-
instance of <code>Functor</code> so that everytime we use
496+
instance of <code>Functor</code> so that every time we use
497497
<code>fmap</code>, the function gets applied to the second field,
498498
whereas the first field gets increased by 1.</p>
499499
<pre class="haskell:hs"><code>instance Functor CMaybe where
@@ -844,7 +844,7 @@ <h2 id="applicative-functors">Applicative functors</h2>
844844
<code>Maybe</code>. There are loads of other instances of
845845
<code>Applicative</code>, so let’s go and meet them!</p>
846846
<p>Lists (actually the list type constructor, <code>[]</code>) are
847-
applicative functors. What a suprise! Here’s how <code>[]</code> is an
847+
applicative functors. What a surprise! Here’s how <code>[]</code> is an
848848
instance of <code>Applicative</code>:</p>
849849
<pre class="haskell:hs"><code>instance Applicative [] where
850850
pure x = [x]
@@ -1557,14 +1557,14 @@ <h3 id="on-newtype-laziness">On newtype laziness</h3>
15571557
<em>data</em>. The only thing that can be done with <em>newtype</em> is
15581558
turning an existing type into a new type, so internally, Haskell can
15591559
represent the values of types defined with <em>newtype</em> just like
1560-
the original ones, only it has to keep in mind that the their types are
1561-
now distinct. This fact means that not only is <em>newtype</em> faster,
1562-
it’s also lazier. Let’s take a look at what this means.</p>
1560+
the original ones, only it has to keep in mind that the types are now
1561+
distinct. This fact means that not only is <em>newtype</em> faster, it’s
1562+
also lazier. Let’s take a look at what this means.</p>
15631563
<p>Like we’ve said before, Haskell is lazy by default, which means that
15641564
only when we try to actually print the results of our functions will any
1565-
computation take place. Furthemore, only those computations that are
1565+
computation take place. Furthermore, only those computations that are
15661566
necessary for our function to tell us the result will get carried out.
1567-
The <code>undefined</code> value in Haskell represents an erronous
1567+
The <code>undefined</code> value in Haskell represents an erroneous
15681568
computation. If we try to evaluate it (that is, force Haskell to
15691569
actually compute it) by printing it to the terminal, Haskell will throw
15701570
a hissy fit (technically referred to as an exception):</p>
@@ -2227,7 +2227,7 @@ <h3 id="using-monoids-to-fold-data-structures">Using monoids to fold
22272227
folds, the <code class="label class">Foldable</code> type class was
22282228
introduced. Much like <code>Functor</code> is for things that can be
22292229
mapped over, <code>Foldable</code> is for things that can be folded up!
2230-
It can be found in <code>Data.Foldable</code> and because it export
2230+
It can be found in <code>Data.Foldable</code> and because it exports
22312231
functions whose names clash with the ones from the <code>Prelude</code>,
22322232
it’s best imported qualified (and served with basil):</p>
22332233
<pre class="haskell:hs"><code>import qualified Foldable as F</code></pre>
@@ -2307,23 +2307,23 @@ <h3 id="using-monoids-to-fold-data-structures">Using monoids to fold
23072307
whole tree down to one single monoid value? When we were doing
23082308
<code>fmap</code> over our tree, we applied the function that we were
23092309
mapping to a node and then we recursively mapped the function over the
2310-
left sub-tree as well as the right one. Here, we’re tasked with not only
2310+
left subtree as well as the right one. Here, we’re tasked with not only
23112311
mapping a function, but with also joining up the results into a single
23122312
monoid value by using <code>mappend</code>. First we consider the case
23132313
of the empty tree — a sad and lonely tree that has no values or
2314-
sub-trees. It doesn’t hold any value that we can give to our
2314+
subtrees. It doesn’t hold any value that we can give to our
23152315
monoid-making function, so we just say that if our tree is empty, the
23162316
monoid value it becomes is <code>mempty</code>.</p>
23172317
<p>The case of a non-empty node is a bit more interesting. It contains
2318-
two sub-trees as well as a value. In this case, we recursively
2318+
two subtrees as well as a value. In this case, we recursively
23192319
<code>foldMap</code> the same function <code>f</code> over the left and
2320-
the right sub-trees. Remember, our <code>foldMap</code> results in a
2320+
the right subtrees. Remember, our <code>foldMap</code> results in a
23212321
single monoid value. We also apply our function <code>f</code> to the
23222322
value in the node. Now we have three monoid values (two from our
2323-
sub-trees and one from applying <code>f</code> to the value in the node)
2323+
subtrees and one from applying <code>f</code> to the value in the node)
23242324
and we just have to bang them together into a single value. For this
2325-
purpose we use <code>mappend</code>, and naturally the left sub-tree
2326-
comes first, then the node value and then the right sub-tree.</p>
2325+
purpose we use <code>mappend</code>, and naturally the left subtree
2326+
comes first, then the node value and then the right subtree.</p>
23272327
<p>Notice that we didn’t have to provide the function that takes a value
23282328
and returns a monoid value. We receive that function as a parameter to
23292329
<code>foldMap</code> and all we have to decide is where to apply that

markdown/generated_html/higher-order-functions.html

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h2 id="curried-functions">Curried functions</h2>
113113
<pre class="haskell:hs"><code>compareWithHundred :: (Num a, Ord a) =&gt; a -&gt; Ordering
114114
compareWithHundred x = compare 100 x</code></pre>
115115
<p>If we call it with <code>99</code>, it returns a <code>GT</code>.
116-
Simple stuff. Notice that the <code>x</code> is on the right hand side
116+
Simple stuff. Notice that the <code>x</code> is on the right-hand side
117117
on both sides of the equation. Now let’s think about what
118118
<code>compare 100</code> returns. It returns a function that takes a
119119
number and compares it with <code>100</code>. Wow! Isn’t that the
@@ -354,13 +354,14 @@ <h2 id="maps-and-filters">Maps and filters</h2>
354354
&quot;uagameasadifeent&quot;
355355
ghci&gt; filter (`elem` [&#39;A&#39;..&#39;Z&#39;]) &quot;i Laugh At you Because u R All The Same&quot;
356356
&quot;LABRATS&quot;</code></pre>
357-
<p>All of this could also be achived with list comprehensions by the use
358-
of predicates. There’s no set rule for when to use <code>map</code> and
359-
<code>filter</code> versus using list comprehension, you just have to
360-
decide what’s more readable depending on the code and the context. The
361-
<code>filter</code> equivalent of applying several predicates in a list
362-
comprehension is either filtering something several times or joining the
363-
predicates with the logical <code>&amp;&amp;</code> function.</p>
357+
<p>All of this could also be achieved with list comprehensions by the
358+
use of predicates. There’s no set rule for when to use <code>map</code>
359+
and <code>filter</code> versus using list comprehension, you just have
360+
to decide what’s more readable depending on the code and the context.
361+
The <code>filter</code> equivalent of applying several predicates in a
362+
list comprehension is either filtering something several times or
363+
joining the predicates with the logical <code>&amp;&amp;</code>
364+
function.</p>
364365
<p>Remember our quicksort function from the <a
365366
href="recursion.html">previous chapter</a>? We used list comprehensions
366367
to filter out the list elements that are smaller than (or equal to) and
@@ -671,7 +672,7 @@ <h2 id="folds">Only folds and horses</h2>
671672
<p>If we’re mapping <code>(+3)</code> to <code>[1,2,3]</code>, we
672673
approach the list from the right side. We take the last element, which
673674
is <code>3</code> and apply the function to it, which ends up being
674-
<code>6</code>. Then, we prepend it to the accumulator, which is was
675+
<code>6</code>. Then, we prepend it to the accumulator, which is
675676
<code>[]</code>. <code>6:[]</code> is <code>[6]</code> and that’s now
676677
the accumulator. We apply <code>(+3)</code> to <code>2</code>, that’s
677678
<code>5</code> and we prepend (<code>:</code>) it to the accumulator, so
@@ -801,8 +802,8 @@ <h2 id="folds">Only folds and horses</h2>
801802
<p>We use <code>takeWhile</code> here instead of <code>filter</code>
802803
because <code>filter</code> doesn’t work on infinite lists. Even though
803804
we know the list is ascending, <code>filter</code> doesn’t, so we use
804-
<code>takeWhile</code> to cut the scanlist off at the first occurence of
805-
a sum greater than 1000.</p>
805+
<code>takeWhile</code> to cut the scanlist off at the first occurrence
806+
of a sum greater than 1000.</p>
806807
<h2 id="function-application">Function application with $</h2>
807808
<p>Alright, next up, we’ll take a look at the <code>$</code> function,
808809
also called <em>function application</em>. First of all, let’s check out
@@ -827,10 +828,10 @@ <h2 id="function-application">Function application with $</h2>
827828
keystrokes! When a <code>$</code> is encountered, the expression on its
828829
right is applied as the parameter to the function on its left. How about
829830
<code>sqrt 3 + 4 + 9</code>? This adds together 9, 4 and the square root
830-
of 3. If we want get the square root of <em>3 + 4 + 9</em>, we’d have to
831-
write <code>sqrt (3 + 4 + 9)</code> or if we use <code>$</code> we can
832-
write it as <code>sqrt $ 3 + 4 + 9</code> because <code>$</code> has the
833-
lowest precedence of any operator. That’s why you can imagine a
831+
of 3. If we want to get the square root of <em>3 + 4 + 9</em>, we’d have
832+
to write <code>sqrt (3 + 4 + 9)</code> or if we use <code>$</code> we
833+
can write it as <code>sqrt $ 3 + 4 + 9</code> because <code>$</code> has
834+
the lowest precedence of any operator. That’s why you can imagine a
834835
<code>$</code> being sort of the equivalent of writing an opening
835836
parentheses and then writing a closing one on the far right side of the
836837
expression.</p>
@@ -921,8 +922,8 @@ <h2 id="composition">Function composition</h2>
921922
the function as <code>sum' = foldl (+) 0</code> is called writing it in
922923
point free style. How would we write this in point free style?</p>
923924
<pre class="haskell:hs"><code>fn x = ceiling (negate (tan (cos (max 50 x))))</code></pre>
924-
<p>We can’t just get rid of the <code>x</code> on both right right
925-
sides. The <code>x</code> in the function body has parentheses after it.
925+
<p>We can’t just get rid of the <code>x</code> on both right sides. The
926+
<code>x</code> in the function body has parentheses after it.
926927
<code>cos (max 50)</code> wouldn’t make sense. You can’t get the cosine
927928
of a function. What we can do is express <code>fn</code> as a
928929
composition of functions.</p>
@@ -935,7 +936,7 @@ <h2 id="composition">Function composition</h2>
935936
writing a function in point free style can be less readable if a
936937
function is too complex. That’s why making long chains of function
937938
composition is discouraged, although I plead guilty of sometimes being
938-
too composition-happy. The prefered style is to use <em>let</em>
939+
too composition-happy. The preferred style is to use <em>let</em>
939940
bindings to give labels to intermediary results or split the problem
940941
into sub-problems and then put it together so that the function makes
941942
sense to someone reading it instead of just making a huge composition

0 commit comments

Comments
 (0)