diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84cbd40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/.idea diff --git a/docs/a-fistful-of-monads.html b/docs/a-fistful-of-monads.html index 152f6c2..70ac4db 100644 --- a/docs/a-fistful-of-monads.html +++ b/docs/a-fistful-of-monads.html @@ -1,11 +1,11 @@ - + A Fistful of Monads - Learn You a Haskell for Great Good! - @@ -47,7 +47,7 @@

A Fistful of Monads

applicative functors are only beefed up functors.

-more cool than u +more cool than u

When we started off with functors, we saw that it's possible to map functions @@ -2153,11 +2153,11 @@

Associativity

diff --git a/docs/chapters.html b/docs/chapters.html index ced6cf2..d5eb1ef 100644 --- a/docs/chapters.html +++ b/docs/chapters.html @@ -1,11 +1,11 @@ - + Chapters - Learn You a Haskell for Great Good! - @@ -165,7 +165,7 @@

Learn You a Haskell for Great Good!

- This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License because I couldn't find a license with an even longer name. + This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License because I couldn't find a licence with an even longer name.

@@ -177,11 +177,11 @@

Learn You a Haskell for Great Good!

diff --git a/docs/faq.html b/docs/faq.html index 9593b05..9e174e6 100644 --- a/docs/faq.html +++ b/docs/faq.html @@ -1,11 +1,11 @@ - + FAQ - Learn You a Haskell for Great Good! - @@ -19,9 +19,9 @@

FAQ

turtle???

Can I put this tutorial on my site or change it or whatever?

-

Sure, it's licensed under a creative commons license, so you can share and change this, as long as you do it with a smile on your face and for non-commercial purposes.

+

Sure, it's licensed under a creative commons licence, so you can share and change this, as long as you do it with a smile on your face and for non-commercial purposes.

Do you recommend any other Haskell reading material?

-

There are loads of awesome tutorials out there, but I'd just like to point out how great Real World Haskell is. It's really great. I feel it complements this tutorial nicely. This tutorial focuses mainly on using simple examples to ease beginners into learning Haskell, whereas Real World Haskell really shows you how to do useful stuff with it.

+

There are loads of awesome tutorials out there, but I'd just like to point out how great Real World Haskell is. It's really great. I feel it complements this tutorial nicely. This tutorial focuses mainly on using simple examples to ease beginners into learning Haskell, whereas Real World Haskell really shows you how to do useful stuff with it.

Another great Haskell resource is Try Haskell, which allows you to try Haskell right in your browser and offers a rad interactive walkthrough.

How do I get in touch with you?

The best way would be to shoot me an email to bonus at learnyouahaskell dot com. I kinda suck at email though, so please, please don't be mad if I don't reply in a timely fashion!

@@ -46,11 +46,11 @@

Tell me about yourself!

diff --git a/docs/for-a-few-monads-more.html b/docs/for-a-few-monads-more.html index c406bed..b1af115 100644 --- a/docs/for-a-few-monads-more.html +++ b/docs/for-a-few-monads-more.html @@ -1,11 +1,11 @@ - + For a Few Monads More - Learn You a Haskell for Great Good! - @@ -3109,11 +3109,11 @@

Making monads

diff --git a/docs/functionally-solving-problems.html b/docs/functionally-solving-problems.html index 6558c7b..d3aff45 100644 --- a/docs/functionally-solving-problems.html +++ b/docs/functionally-solving-problems.html @@ -1,11 +1,11 @@ - + Functionally Solving Problems - Learn You a Haskell for Great Good! - @@ -36,7 +36,7 @@

Functionally Solving Problems

Reverse Polish notation calculator

Usually when we write mathematical expressions in school, we write them in an infix manner. For instance, we write 10 - (4 + 3) * 2. +, * and - are infix operators, just like the infix functions we met in Haskell (+, `elem`, 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.

Reverse Polish notation 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: 10 4 3 + 2 * -. 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 onto the stack. When we encounter an operator, take the two numbers that are on top of the stack (we also say that we pop 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.

-this expression +this expression

Let's go over the expression 10 4 3 + 2 * - together! First we push 10 onto the stack and the stack is now 10. The next item is 4, so we push it to the stack as well. The stack is now 10, 4. We do the same with 3 and the stack is now 10, 4, 3. And now, we encounter an operator, namely +! We pop the two top numbers from the stack (so now the stack is just 10), add those numbers together and push that result to the stack. The stack is now 10, 7. We push 2 to the stack, the stack for now is 10, 7, 2. We've encountered an operator again, so let's pop 7 and 2 off the stack, multiply them and push that result to the stack. Multiplying 7 and 2 produces a 14, so the stack we have now is 10, 14. Finally, there's a -. We pop 10 and 14 from the stack, subtract 14 from 10 and push that back. The number on the stack is now -4 and because there are no more numbers or operators in our expression, that's our result!

Now that we know how we'd calculate any RPN expression by hand, let's think about how we could make a Haskell function that takes as its parameter a string that contains an RPN expression, like "10 4 3 + 2 * -" and gives us back its result.

What would the type of that function be? We want it to take a string as a parameter and produce a number as its result. So it will probably be something like solveRPN :: (Num a) => String -> a.

@@ -156,7 +156,7 @@

Functionally Solving Problems

In the RPN calculator section, we first figured out that when calculating an expression by hand, we'd keep a sort of stack in our minds and then go over the expression one item at a time. We decided to use a list of strings to represent our expression. Finally, we used a left fold to walk over the list of strings while keeping a stack to produce a solution.

Okay, so how would we figure out the shortest path from Heathrow to London by hand? Well, we can just sort of look at the whole picture and try to guess what the shortest path is and hopefully we'll make a guess that's right. That solution works for very small inputs, but what if we have a road that has 10,000 sections? Yikes! We also won't be able to say for certain that our solution is the optimal one, we can just sort of say that we're pretty sure.

That's not a good solution then. Here's a simplified picture of our road system:

-roads +roads

Alright, can you figure out what the shortest path to the first crossroads (the first blue dot on A, marked A1) on road A is? That's pretty trivial. We just see if it's shorter to go directly forward on A or if it's shorter to go forward on B and then cross over. Obviously, it's cheaper to go forward via B and then cross over because that takes 40 minutes, whereas going directly via A takes 50 minutes. What about crossroads B1? Same thing. We see that it's a lot cheaper to just go directly via B (incurring a cost of 10 minutes), because going via A and then crossing over would take us a whole 80 minutes!

Now we know what the cheapest path to A1 is (go via B and then cross over, so we'll say that's B, C with a cost of 40) and we know what the cheapest path to B1 is (go directly via B, so that's just B, going at 10). Does this knowledge help us at all if we want to know the cheapest path to the next crossroads on both main roads? Gee golly, it sure does!

Let's see what the shortest path to A2 would be. To get to A2, we'll either go directly to A2 from A1 or we'll go forward from B1 and then cross over (remember, we can only move forward or cross to the other side). And because we know the cost to A1 and B1, we can easily figure out what the best path to A2 is. It costs 40 to get to A1 and then 5 to get from A1 to A2, so that's B, C, A for a cost of 45. It costs only 10 to get to B1, but then it would take an additional 110 minutes to go to B2 and then cross over! So obviously, the cheapest path to A2 is B, C, A. In the same way, the cheapest way to B2 is to go forward from A1 and then cross over.

@@ -313,11 +313,11 @@

Functionally Solving Problems

diff --git a/docs/functors-applicative-functors-and-monoids.html b/docs/functors-applicative-functors-and-monoids.html index 6d0c7bb..f6e8870 100644 --- a/docs/functors-applicative-functors-and-monoids.html +++ b/docs/functors-applicative-functors-and-monoids.html @@ -1,11 +1,11 @@ - + Functors, Applicative Functors and Monoids - Learn You a Haskell for Great Good! - @@ -2152,11 +2152,11 @@

Using monoids to fold data structures

diff --git a/docs/higher-order-functions.html b/docs/higher-order-functions.html index 1c1ebaa..86fa6e0 100644 --- a/docs/higher-order-functions.html +++ b/docs/higher-order-functions.html @@ -1,11 +1,11 @@ - + Higher Order Functions - Learn You a Haskell for Great Good! - @@ -491,11 +491,11 @@

Higher order functions

diff --git a/docs/index.html b/docs/index.html index 1da96f2..d400f5b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,5 +1,6 @@ - - + + @@ -37,7 +38,7 @@ - @@ -1321,11 +1321,11 @@

Input and Output

diff --git a/docs/introduction.html b/docs/introduction.html index 4f22a1e..060643f 100644 --- a/docs/introduction.html +++ b/docs/introduction.html @@ -1,11 +1,11 @@ - + Introduction - Learn You a Haskell for Great Good! - @@ -99,11 +99,11 @@

About this tutorial

diff --git a/docs/making-our-own-types-and-typeclasses.html b/docs/making-our-own-types-and-typeclasses.html index 6159814..92987fa 100644 --- a/docs/making-our-own-types-and-typeclasses.html +++ b/docs/making-our-own-types-and-typeclasses.html @@ -1,11 +1,11 @@ - + Making Our Own Types and Typeclasses - Learn You a Haskell for Great Good! - @@ -1064,11 +1064,11 @@

Making Our Own Types and Typeclasses

diff --git a/docs/modules.html b/docs/modules.html index 3cc87ed..cd500f0 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,11 +1,11 @@ - + Modules - Learn You a Haskell for Great Good! - @@ -930,11 +930,11 @@

Modules

diff --git a/docs/recursion.html b/docs/recursion.html index 4ea9586..e82e2be 100644 --- a/docs/recursion.html +++ b/docs/recursion.html @@ -1,11 +1,11 @@ - + Recursion - Learn You a Haskell for Great Good! - @@ -163,11 +163,11 @@

Recursion

diff --git a/docs/starting-out.html b/docs/starting-out.html index 0b9ac98..c9e4c6a 100644 --- a/docs/starting-out.html +++ b/docs/starting-out.html @@ -1,11 +1,11 @@ - + Starting Out - Learn You a Haskell for Great Good! - @@ -559,11 +559,11 @@

Starting Out

diff --git a/docs/syntax-in-functions.html b/docs/syntax-in-functions.html index db4f78f..0307be4 100644 --- a/docs/syntax-in-functions.html +++ b/docs/syntax-in-functions.html @@ -1,11 +1,11 @@ - + Syntax in Functions - Learn You a Haskell for Great Good! - @@ -408,11 +408,11 @@

Syntax in Functions

diff --git a/docs/types-and-typeclasses.html b/docs/types-and-typeclasses.html index 83e28e4..273f012 100644 --- a/docs/types-and-typeclasses.html +++ b/docs/types-and-typeclasses.html @@ -1,11 +1,11 @@ - + Types and Typeclasses - Learn You a Haskell for Great Good! - @@ -307,11 +307,11 @@

Types and Typeclasses

diff --git a/docs/zippers.html b/docs/zippers.html index c8eae1a..2f67075 100644 --- a/docs/zippers.html +++ b/docs/zippers.html @@ -1,11 +1,11 @@ - + Zippers - Learn You a Haskell for Great Good! - @@ -1188,11 +1188,11 @@

Watch your step