@@ -206,7 +206,7 @@ <h2 id="functors-redux">Functors redux</h2>
206206< code > r -> a</ code > can be rewritten as < code > (->) r a</ code > ,
207207much like we can write < code > 2 + 3</ code > as < code > (+) 2 3</ code > . When
208208we look at it as < code > (->) r a</ code > , we can see
209- < code > (->)</ code > in a slighty different light, because we see that
209+ < code > (->)</ code > in a slightly different light, because we see that
210210it’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
212212to 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,
494494and if we use the < code > CJust</ code > constructor, the first field is an
495495integer 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,
498498whereas 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
848848instance 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
15581558turning an existing type into a new type, so internally, Haskell can
15591559represent 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
15641564only 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
15661566necessary 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
15681568computation. If we try to evaluate it (that is, force Haskell to
15691569actually compute it) by printing it to the terminal, Haskell will throw
15701570a 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
22272227folds, the < code class ="label class "> Foldable</ code > type class was
22282228introduced. Much like < code > Functor</ code > is for things that can be
22292229mapped 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
22312231functions whose names clash with the ones from the < code > Prelude</ code > ,
22322232it’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
23072307whole 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
23092309mapping 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
23112311mapping a function, but with also joining up the results into a single
23122312monoid value by using < code > mappend</ code > . First we consider the case
23132313of 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
23152315monoid-making function, so we just say that if our tree is empty, the
23162316monoid 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
23212321single monoid value. We also apply our function < code > f</ code > to the
23222322value 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)
23242324and 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
23282328and 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
0 commit comments