@@ -206,7 +206,7 @@ <h2 id="functors-redux">Functors redux</h2>
206
206
< code > r -> a</ code > can be rewritten as < code > (->) r a</ code > ,
207
207
much like we can write < code > 2 + 3</ code > as < code > (+) 2 3</ code > . When
208
208
we 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
210
210
it’s just a type constructor that takes two type parameters, just like
211
211
< code > Either</ code > . But remember, we said that a type constructor has
212
212
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>
493
493
< p > If we use the < code > CNothing</ code > constructor, there are no fields,
494
494
and if we use the < code > CJust</ code > constructor, the first field is an
495
495
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
497
497
< code > fmap</ code > , the function gets applied to the second field,
498
498
whereas the first field gets increased by 1.</ p >
499
499
< pre class ="haskell:hs "> < code > instance Functor CMaybe where
@@ -844,7 +844,7 @@ <h2 id="applicative-functors">Applicative functors</h2>
844
844
< code > Maybe</ code > . There are loads of other instances of
845
845
< code > Applicative</ code > , so let’s go and meet them!</ p >
846
846
< 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
848
848
instance of < code > Applicative</ code > :</ p >
849
849
< pre class ="haskell:hs "> < code > instance Applicative [] where
850
850
pure x = [x]
@@ -1557,14 +1557,14 @@ <h3 id="on-newtype-laziness">On newtype laziness</h3>
1557
1557
< em > data</ em > . The only thing that can be done with < em > newtype</ em > is
1558
1558
turning an existing type into a new type, so internally, Haskell can
1559
1559
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 >
1563
1563
< p > Like we’ve said before, Haskell is lazy by default, which means that
1564
1564
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
1566
1566
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
1568
1568
computation. If we try to evaluate it (that is, force Haskell to
1569
1569
actually compute it) by printing it to the terminal, Haskell will throw
1570
1570
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
2227
2227
folds, the < code class ="label class "> Foldable</ code > type class was
2228
2228
introduced. Much like < code > Functor</ code > is for things that can be
2229
2229
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
2231
2231
functions whose names clash with the ones from the < code > Prelude</ code > ,
2232
2232
it’s best imported qualified (and served with basil):</ p >
2233
2233
< 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
2307
2307
whole tree down to one single monoid value? When we were doing
2308
2308
< code > fmap</ code > over our tree, we applied the function that we were
2309
2309
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
2311
2311
mapping a function, but with also joining up the results into a single
2312
2312
monoid value by using < code > mappend</ code > . First we consider the case
2313
2313
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
2315
2315
monoid-making function, so we just say that if our tree is empty, the
2316
2316
monoid value it becomes is < code > mempty</ code > .</ p >
2317
2317
< 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
2319
2319
< 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
2321
2321
single monoid value. We also apply our function < code > f</ code > to the
2322
2322
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)
2324
2324
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 >
2327
2327
< p > Notice that we didn’t have to provide the function that takes a value
2328
2328
and returns a monoid value. We receive that function as a parameter to
2329
2329
< code > foldMap</ code > and all we have to decide is where to apply that
0 commit comments