diff --git a/markdown/generate.sh b/markdown/generate.sh old mode 100644 new mode 100755 index 8205d7d..1d98d79 --- a/markdown/generate.sh +++ b/markdown/generate.sh @@ -10,27 +10,27 @@ cp source_md/chapters_head.md $chapterfile for i in ${!filename[@]} do sourcemd=source_md/${filename[$i]}.md - - title[$i]=$(sed -n '/^# /s/# //p;' $sourcemd | sed 's/{.*//' | sed 's/ *$//g') - chnum=$(($i + 1)) - if [[ $chnum -ge 10 ]]; + title[$i]=$(sed -n '/^# /s/# //p;' $sourcemd | sed 's/{.*//; s/ *$//g') + + chnum=$((i + 1)) + if ((chnum >= 10)) then sp=" " else sp=" " fi - sed -n '/^#\{1,2\} /p' $sourcemd \ - | sed "s/^# *\(.*[^ ]\) *{.*/$chnum.$sp[\1](${filename[$i]}.html)/" \ - | sed "s/^# *\(.*[^ ]\) */$chnum.$sp[\1](${filename[$i]}.html)/" \ - | sed "s/^## *\(.*[^ ]\) *{ *#\(.*\)}/ * [\1](${filename[$i]}.html\#\2)/" \ - >>$chapterfile + grep '^#\{1,2\} ' $sourcemd \ + | sed "s/^# *\(.*[^ ]\) *{.*/$chnum.$sp[\1](${filename[$i]}.html)/; + s/^# *\(.*[^ ]\) */$chnum.$sp[\1](${filename[$i]}.html)/; + s/^## *\(.*[^ ]\) *{ *#\(.*\)}/ * [\1](${filename[$i]}.html\#\2)/" \ + >> $chapterfile done for i in ${!filename[@]} do - if (($i <= 0)) + if ((i <= 0)) then prev_title= prev_filename= @@ -39,7 +39,7 @@ do prev_title="${title[$prev]}" prev_filename=${filename[$prev]} fi - if (($i >= ${#filename[@]} - 1)) + if ((i >= ${#filename[@]} - 1)) then next_title= next_filename= @@ -48,13 +48,13 @@ do next_title="${title[$next]}" next_filename=${filename[$next]} fi - + pandoc -d config/pandoc-defaults.yml --template=config/template.html \ -V footdiv=true -V title="${title[$i]}" \ --metadata title="${title[$i]}$titlesuffix" \ -V prev_title="$prev_title" -V prev_filename=$prev_filename \ -V next_title="$next_title" -V next_filename=$next_filename \ - -o generated_html/${filename[$i]}.html source_md/${filename[$i]}.md + -o generated_html/${filename[$i]}.html source_md/${filename[$i]}.md done cat source_md/chapters_foot.md >>$chapterfile diff --git a/markdown/generated_html/functors-applicative-functors-and-monoids.html b/markdown/generated_html/functors-applicative-functors-and-monoids.html index a9919da..93a501b 100644 --- a/markdown/generated_html/functors-applicative-functors-and-monoids.html +++ b/markdown/generated_html/functors-applicative-functors-and-monoids.html @@ -412,7 +412,7 @@

Functors redux

fmap f (Just x) = Just (f x) fmap f Nothing = Nothing

We imagine that id plays the role of the f -parameter in the implementation. We see that if wee fmap id +parameter in the implementation. We see that if we fmap id over Just x, the result will be Just (id x), and because id just returns its parameter, we can deduce that Just (id x) equals Just x. So now we know diff --git a/markdown/generated_html/higher-order-functions.html b/markdown/generated_html/higher-order-functions.html index 14cb5cf..f0023f8 100644 --- a/markdown/generated_html/higher-order-functions.html +++ b/markdown/generated_html/higher-order-functions.html @@ -155,12 +155,10 @@

Curried functions

instead of binding it to a name with a let or passing it to another function?

ghci> multThree 3 4
-<interactive>:1:0:
-    No instance for (Show (t -> t))
-      arising from a use of `print' at <interactive>:1:0-12
-    Possible fix: add an instance declaration for (Show (t -> t))
-    In the expression: print it
-    In a 'do' expression: print it
+<interactive>:1:1: error: [GHC-39999] + • No instance for ‘Show (a0 -> a0)’ arising from a use of ‘print’ + (maybe you haven't applied a function to enough arguments?) + • In a stmt of an interactive GHCi command: print it

GHCI is telling us that the expression produced a function of type a -> a but it doesn’t know how to print it to the screen. Functions aren’t instances of the Show typeclass, diff --git a/markdown/generated_html/introduction.html b/markdown/generated_html/introduction.html index 147f497..e3a34db 100644 --- a/markdown/generated_html/introduction.html +++ b/markdown/generated_html/introduction.html @@ -56,7 +56,9 @@

About this tutorial

Haskell.

The channel #haskell on the Libera.Chat network is a great place to ask questions if you’re feeling stuck. People there are extremely nice, -patient and understanding to newbies.

+patient and understanding to newbies. If IRC it not your cup of tea, https://discourse.haskell.org +is a popular community forum with a section for learners.

I failed to learn Haskell approximately 2 times before finally grasping it because it all just seemed too weird to me and I didn’t get it. But then once it just “clicked” and after getting over that initial diff --git a/markdown/generated_html/making-our-own-types-and-typeclasses.html b/markdown/generated_html/making-our-own-types-and-typeclasses.html index f92ee5b..7dfa5d5 100644 --- a/markdown/generated_html/making-our-own-types-and-typeclasses.html +++ b/markdown/generated_html/making-our-own-types-and-typeclasses.html @@ -1012,8 +1012,8 @@

Recursive data structures

ghci> let b = 6 :-: 7 :-: Empty ghci> a .++ b (:-:) 3 ((:-:) 4 ((:-:) 5 ((:-:) 6 ((:-:) 7 Empty)))) -

Nice. Is nice. If we wanted, we could implement all of the functions -that operate on lists on our own list type.

+

Nice. If we wanted, we could implement all of the functions that +operate on lists on our own list type.

Notice how we pattern matched on (x :-: xs). That works because pattern matching is actually about matching constructors. We can match on :-: because it is a constructor for our own list diff --git a/markdown/generated_html/starting-out.html b/markdown/generated_html/starting-out.html index add4522..3a6471f 100644 --- a/markdown/generated_html/starting-out.html +++ b/markdown/generated_html/starting-out.html @@ -96,8 +96,10 @@

Ready, set, go!

True

What about doing 5 + "llama" or 5 == True? Well, if we try the first snippet, we get a big scary error message!

-
• No instance for (Num String) arising from a use of ‘+’
-    • In the expression: 5 + "llama"
+
<interactive>:1:1: error: [GHC-39999]
+    • No instance for ‘Num String’ arising from the literal ‘5’
+    • In the first argument of ‘(+)’, namely ‘5’
+      In the expression: 5 + "llama"
       In an equation for ‘it’: it = 5 + "llama"

Yikes! What GHCI is telling us here is that "llama" is not a number and so it doesn’t know how to add it to 5. Even if it @@ -113,6 +115,13 @@

Ready, set, go!

sneaky and can act like an integer or a floating-point number. 4.0 can’t act like an integer, so 5 is the one that has to adapt.

+
+

Note: GHC errors are all assigned unique identifiers +such as GHC-39999 above. Whenever you are stuck with a +stubborn error, you can look it up at https://errors.haskell.org/ to +learn typical causes and solutions.

+

You may not have known it but we’ve been using functions now all along. For instance, * is a function that takes two numbers and multiplies them. As you’ve seen, we call it by sandwiching it @@ -664,8 +673,9 @@

Tuples

brackets, we use parentheses: [(1,2),(8,11),(4,5)]. What if we tried to make a shape like [(1,2),(8,11,5),(4,5)]? Well, we’d get this error:

-
• Couldn't match expected type ‘(a, b)’
-                  with actual type ‘(a0, b0, c0)’
+
<interactive>:1:8: error: [GHC-83865]
+    • Couldn't match expected type: (a, b)
+                  with actual type: (a0, b0, c0)
     • In the expression: (8, 11, 5)
       In the expression: [(1, 2), (8, 11, 5), (4, 5)]
       In an equation for ‘it’: it = [(1, 2), (8, 11, 5), (4, 5)]
diff --git a/markdown/generated_html/types-and-typeclasses.html b/markdown/generated_html/types-and-typeclasses.html
index db74b96..dee3ef2 100644
--- a/markdown/generated_html/types-and-typeclasses.html
+++ b/markdown/generated_html/types-and-typeclasses.html
@@ -402,13 +402,12 @@ 

Typeclasses 101

floating point types to work together nicely. For instance, the length function has a type declaration of length :: [a] -> Int instead of having a more general -type of (Num b) => length :: [a] -> b. I think that’s -there for historical reasons or something, although in my opinion, it’s -pretty stupid. Anyway, if we try to get a length of a list and then add -it to 3.2, we’ll get an error because we tried to add -together an Int and a floating point number. So to get -around this, we do fromIntegral (length [1,2,3,4]) + 3.2 -and it all works out.

+type of (Num b) => length :: [a] -> b. If we try to +get a length of a list and then add it to 3.2, we’ll get an +error because we tried to add together an Int and a +floating point number. So to get around this, we do +fromIntegral (length [1,2,3,4]) + 3.2 and it all works +out.

Notice that fromIntegral has several class constraints in its type signature. That’s completely valid and as you can see, the class constraints are separated by commas inside the parentheses.