Skip to content

Commit 9fca6e8

Browse files
committed
fix: generate.sh
1 parent 4a99fe8 commit 9fca6e8

10 files changed

+120
-87
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from: markdown-implicit_figures
22
to: html
3-
highlight-style: null
43
standalone: true

markdown/config/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
22
"https://www.w3.org/TR/html4/strict.dtd">
3-
<html lange="en">
3+
<html lang="en">
44
<head>
55
<title>$title$ - Learn You a Haskell for Great Good!</title>
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

markdown/generate.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -e
23

34
mapfile -t filename <config/file-list.txt
45

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ <h2 id="functors-redux">Functors redux</h2>
413413
fmap f (Just x) = Just (f x)
414414
fmap f Nothing = Nothing</code></pre>
415415
<p>We imagine that <code>id</code> plays the role of the <code>f</code>
416-
parameter in the implementation. We see that if wee <code>fmap id</code>
416+
parameter in the implementation. We see that if we <code>fmap id</code>
417417
over <code>Just x</code>, the result will be <code>Just (id x)</code>,
418418
and because <code>id</code> just returns its parameter, we can deduce
419419
that <code>Just (id x)</code> equals <code>Just x</code>. So now we know

markdown/generated_html/higher-order-functions.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,10 @@ <h2 id="curried-functions">Curried functions</h2>
156156
instead of binding it to a name with a <em>let</em> or passing it to
157157
another function?</p>
158158
<pre class="haskell:hs"><code>ghci&gt; multThree 3 4
159-
&lt;interactive&gt;:1:0:
160-
No instance for (Show (t -&gt; t))
161-
arising from a use of `print&#39; at &lt;interactive&gt;:1:0-12
162-
Possible fix: add an instance declaration for (Show (t -&gt; t))
163-
In the expression: print it
164-
In a &#39;do&#39; expression: print it</code></pre>
159+
&lt;interactive&gt;:1:1: error: [GHC-39999]
160+
• No instance for ‘Show (a0 -&gt; a0)’ arising from a use of ‘print’
161+
(maybe you haven&#39;t applied a function to enough arguments?)
162+
• In a stmt of an interactive GHCi command: print it</code></pre>
165163
<p>GHCI is telling us that the expression produced a function of type
166164
<code>a -&gt; a</code> but it doesn’t know how to print it to the
167165
screen. Functions aren’t instances of the <code>Show</code> typeclass,

markdown/generated_html/introduction.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ <h2 id="about-this-tutorial">About this tutorial</h2>
5757
Haskell.</p>
5858
<p>The channel #haskell on the Libera.Chat network is a great place to
5959
ask questions if you’re feeling stuck. People there are extremely nice,
60-
patient and understanding to newbies.</p>
60+
patient and understanding to newbies. If IRC it not your cup of tea, <a
61+
href="https://discourse.haskell.org">https://discourse.haskell.org</a>
62+
is a popular community forum with a section for learners.</p>
6163
<p>I failed to learn Haskell approximately 2 times before finally
6264
grasping it because it all just seemed too weird to me and I didn’t get
6365
it. But then once it just “clicked” and after getting over that initial

markdown/generated_html/making-our-own-types-and-typeclasses.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,8 @@ <h2 id="recursive-data-structures">Recursive data structures</h2>
10131013
ghci&gt; let b = 6 :-: 7 :-: Empty
10141014
ghci&gt; a .++ b
10151015
(:-:) 3 ((:-:) 4 ((:-:) 5 ((:-:) 6 ((:-:) 7 Empty))))</code></pre>
1016-
<p>Nice. Is nice. If we wanted, we could implement all of the functions
1017-
that operate on lists on our own list type.</p>
1016+
<p>Nice. If we wanted, we could implement all of the functions that
1017+
operate on lists on our own list type.</p>
10181018
<p>Notice how we pattern matched on <code>(x :-: xs)</code>. That works
10191019
because pattern matching is actually about matching constructors. We can
10201020
match on <code>:-:</code> because it is a constructor for our own list

markdown/generated_html/starting-out.html

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ <h2 id="ready-set-go">Ready, set, go!</h2>
9797
True</code></pre>
9898
<p>What about doing <code>5 + "llama"</code> or <code>5 == True</code>?
9999
Well, if we try the first snippet, we get a big scary error message!</p>
100-
<pre class="haskell: ghci"><code>• No instance for (Num String) arising from a use of ‘+’
101-
• In the expression: 5 + &quot;llama&quot;
100+
<pre class="haskell: ghci"><code>&lt;interactive&gt;:1:1: error: [GHC-39999]
101+
• No instance for ‘Num String’ arising from the literal ‘5’
102+
• In the first argument of ‘(+)’, namely ‘5’
103+
In the expression: 5 + &quot;llama&quot;
102104
In an equation for ‘it’: it = 5 + &quot;llama&quot;</code></pre>
103105
<p>Yikes! What GHCI is telling us here is that <code>"llama"</code> is
104106
not a number and so it doesn’t know how to add it to 5. Even if it
@@ -114,6 +116,13 @@ <h2 id="ready-set-go">Ready, set, go!</h2>
114116
sneaky and can act like an integer or a floating-point number.
115117
<code>4.0</code> can’t act like an integer, so <code>5</code> is the one
116118
that has to adapt.</p>
119+
<div class="hintbox">
120+
<p><strong>Note:</strong> GHC errors are all assigned unique identifiers
121+
such as <code>GHC-39999</code> above. Whenever you are stuck with a
122+
stubborn error, you can look it up at <a
123+
href="https://errors.haskell.org/">https://errors.haskell.org/</a> to
124+
learn typical causes and solutions.</p>
125+
</div>
117126
<p>You may not have known it but we’ve been using functions now all
118127
along. For instance, <code>*</code> is a function that takes two numbers
119128
and multiplies them. As you’ve seen, we call it by sandwiching it
@@ -179,7 +188,8 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
179188
<p>In the previous section we got a basic feel for calling functions.
180189
Now let’s try making our own! Open up your favorite text editor and
181190
punch in this function that takes a number and multiplies it by two.</p>
182-
<pre class="haskell: hs"><code>doubleMe x = x + x</code></pre>
191+
<div class="sourceCode" id="cb10"><pre
192+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>doubleMe x <span class="ot">=</span> x <span class="op">+</span> x</span></code></pre></div>
183193
<p>Functions are defined in a similar way that they are called. The
184194
function name is followed by parameters separated by spaces. But when
185195
defining functions, there’s a <code>=</code> and after that we define
@@ -198,7 +208,8 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
198208
numbers (anything that can be considered a number, really), our function
199209
also works on any number. Let’s make a function that takes two numbers
200210
and multiplies each by two and then adds them together.</p>
201-
<pre class="haskell: hs"><code>doubleUs x y = x*2 + y*2</code></pre>
211+
<div class="sourceCode" id="cb12"><pre
212+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>doubleUs x y <span class="ot">=</span> x<span class="op">*</span><span class="dv">2</span> <span class="op">+</span> y<span class="op">*</span><span class="dv">2</span></span></code></pre></div>
202213
<p>Simple. We could have also defined it as
203214
<code>doubleUs x y = x + x + y + y</code>. Testing it out produces
204215
pretty predictable results (remember to append this function to the
@@ -213,7 +224,8 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
213224
<p>As expected, you can call your own functions from other functions
214225
that you made. With that in mind, we could redefine
215226
<code>doubleUs</code> like this:</p>
216-
<pre class="haskell: hs"><code>doubleUs x y = doubleMe x + doubleMe y</code></pre>
227+
<div class="sourceCode" id="cb14"><pre
228+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>doubleUs x y <span class="ot">=</span> doubleMe x <span class="op">+</span> doubleMe y</span></code></pre></div>
217229
<p>This is a very simple example of a common pattern you will see
218230
throughout Haskell. Making basic functions that are obviously correct
219231
and then combining them into more complex functions. This way you also
@@ -228,9 +240,10 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
228240
<p>Now we’re going to make a function that multiplies a number by 2 but
229241
only if that number is smaller than or equal to 100 because numbers
230242
bigger than 100 are big enough as it is!</p>
231-
<pre class="haskell: hs"><code>doubleSmallNumber x = if x &gt; 100
232-
then x
233-
else x*2</code></pre>
243+
<div class="sourceCode" id="cb15"><pre
244+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>doubleSmallNumber x <span class="ot">=</span> <span class="kw">if</span> x <span class="op">&gt;</span> <span class="dv">100</span></span>
245+
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">then</span> x</span>
246+
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span> x<span class="op">*</span><span class="dv">2</span></span></code></pre></div>
234247
<p><img src="assets/images/starting-out/baby.png" class="left"
235248
width="140" height="211" alt="this is you" /></p>
236249
<p>Right here we introduced Haskell’s if statement. You’re probably
@@ -249,7 +262,8 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
249262
that’s why it’s an expression. If we wanted to add one to every number
250263
that’s produced in our previous function, we could have written its body
251264
like this.</p>
252-
<pre class="haskell: hs"><code>doubleSmallNumber&#39; x = (if x &gt; 100 then x else x*2) + 1</code></pre>
265+
<div class="sourceCode" id="cb16"><pre
266+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>doubleSmallNumber&#39; x <span class="ot">=</span> (<span class="kw">if</span> x <span class="op">&gt;</span> <span class="dv">100</span> <span class="kw">then</span> x <span class="kw">else</span> x<span class="op">*</span><span class="dv">2</span>) <span class="op">+</span> <span class="dv">1</span></span></code></pre></div>
253267
<p>Had we omitted the parentheses, it would have added one only if
254268
<code>x</code> wasn’t greater than 100. Note the <code>'</code> at the
255269
end of the function name. That apostrophe doesn’t have any special
@@ -258,7 +272,8 @@ <h2 id="babys-first-functions">Baby’s first functions</h2>
258272
a function (one that isn’t lazy) or a slightly modified version of a
259273
function or a variable. Because <code>'</code> is a valid character in
260274
functions, we can make a function like this.</p>
261-
<pre class="haskell: hs"><code>conanO&#39;Brien = &quot;It&#39;s a-me, Conan O&#39;Brien!&quot;</code></pre>
275+
<div class="sourceCode" id="cb17"><pre
276+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>conanO&#39;Brien <span class="ot">=</span> <span class="st">&quot;It&#39;s a-me, Conan O&#39;Brien!&quot;</span></span></code></pre></div>
262277
<p>There are two noteworthy things here. The first is that in the
263278
function name we didn’t capitalize Conan’s name. That’s because
264279
functions can’t begin with uppercase letters. We’ll see why a bit later.
@@ -512,7 +527,7 @@ <h2 id="texas-ranges">Texas ranges</h2>
512527
you could do <code>[13,26..24*13]</code>. But there’s a better way:
513528
<code>take 24 [13,26..]</code>. Because Haskell is lazy, it won’t try to
514529
evaluate the infinite list immediately because it would never finish.
515-
It’ll wait to see what you want to get out of that infinite lists. And
530+
It’ll wait to see what you want to get out of that infinite list. And
516531
here it sees you just want the first 24 elements and it gladly
517532
obliges.</p>
518533
<p>A handful of functions that produce infinite lists:</p>
@@ -579,8 +594,9 @@ <h2 id="im-a-list-comprehension">I’m a list comprehension</h2>
579594
<code>odd</code> returns <code>True</code> on an odd number and
580595
<code>False</code> on an even one. The element is included in the list
581596
only if all the predicates evaluate to <code>True</code>.</p>
582-
<pre class="haskell: hs"><code>ghci&gt; boomBangs [7..13]
583-
[&quot;BOOM!&quot;,&quot;BOOM!&quot;,&quot;BANG!&quot;,&quot;BANG!&quot;]</code></pre>
597+
<div class="sourceCode" id="cb46"><pre
598+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>ghci<span class="op">&gt;</span> boomBangs [<span class="dv">7</span><span class="op">..</span><span class="dv">13</span>]</span>
599+
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a>[<span class="st">&quot;BOOM!&quot;</span>,<span class="st">&quot;BOOM!&quot;</span>,<span class="st">&quot;BANG!&quot;</span>,<span class="st">&quot;BANG!&quot;</span>]</span></code></pre></div>
584600
<p>We can include several predicates. If we wanted all numbers from 10
585601
to 20 that are not 13, 15 or 19, we’d do:</p>
586602
<pre class="haskell: ghci"><code>ghci&gt; [ x | x &lt;- [10..20], x /= 13, x /= 15, x /= 19]
@@ -610,7 +626,8 @@ <h2 id="im-a-list-comprehension">I’m a list comprehension</h2>
610626
&quot;grouchy pope&quot;,&quot;scheming hobo&quot;,&quot;scheming frog&quot;,&quot;scheming pope&quot;]</code></pre>
611627
<p>I know! Let’s write our own version of <code>length</code>! We’ll
612628
call it <code>length'</code>.</p>
613-
<pre class="haskell: hs"><code>length&#39; xs = sum [1 | _ &lt;- xs]</code></pre>
629+
<div class="sourceCode" id="cb51"><pre
630+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a>length&#39; xs <span class="ot">=</span> <span class="fu">sum</span> [<span class="dv">1</span> <span class="op">|</span> _ <span class="ot">&lt;-</span> xs]</span></code></pre></div>
614631
<p><code>_</code> means that we don’t care what we’ll draw from the list
615632
anyway so instead of writing a variable name that we’ll never use, we
616633
just write <code>_</code>. This function replaces every element of a
@@ -620,7 +637,8 @@ <h2 id="im-a-list-comprehension">I’m a list comprehension</h2>
620637
comprehensions to process and produce strings. Here’s a function that
621638
takes a string and removes everything except uppercase letters from
622639
it.</p>
623-
<pre class="haskell: hs"><code>removeNonUppercase st = [ c | c &lt;- st, c `elem` [&#39;A&#39;..&#39;Z&#39;]]</code></pre>
640+
<div class="sourceCode" id="cb52"><pre
641+
class="sourceCode haskell: hs"><code class="sourceCode haskell"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>removeNonUppercase st <span class="ot">=</span> [ c <span class="op">|</span> c <span class="ot">&lt;-</span> st, c <span class="ot">`elem`</span> [<span class="ch">&#39;A&#39;</span><span class="op">..</span><span class="ch">&#39;Z&#39;</span>]]</span></code></pre></div>
624642
<p>Testing it out:</p>
625643
<pre class="haskell: ghci"><code>ghci&gt; removeNonUppercase &quot;Hahaha! Ahahaha!&quot;
626644
&quot;HA&quot;
@@ -665,8 +683,9 @@ <h2 id="tuples">Tuples</h2>
665683
brackets, we use parentheses: <code>[(1,2),(8,11),(4,5)]</code>. What if
666684
we tried to make a shape like <code>[(1,2),(8,11,5),(4,5)]</code>? Well,
667685
we’d get this error:</p>
668-
<pre class="haskell: ghci"><code>• Couldn&#39;t match expected type ‘(a, b)’
669-
with actual type ‘(a0, b0, c0)’
686+
<pre class="haskell: ghci"><code>&lt;interactive&gt;:1:8: error: [GHC-83865]
687+
• Couldn&#39;t match expected type: (a, b)
688+
with actual type: (a0, b0, c0)
670689
• In the expression: (8, 11, 5)
671690
In the expression: [(1, 2), (8, 11, 5), (4, 5)]
672691
In an equation for ‘it’: it = [(1, 2), (8, 11, 5), (4, 5)]

0 commit comments

Comments
 (0)