Skip to content

Commit 4661270

Browse files
committed
text refinement
1 parent 60cc4e8 commit 4661270

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

source_md/functors-applicative-functors-and-monoids.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ Let's take some time and get properly acquainted with it.
15111511
First of all, we see that only concrete types can be made instances of `Monoid`, because the `m` in the type class definition doesn't take any type parameters.
15121512
This is different from `Functor` and `Applicative`, which require their instances to be type constructors which take one parameter.
15131513
We also see that all `Monoid`s must also be `Semigroup`s, just like all `Applicative`s must be `Functor`s.
1514-
This is because monoids are a special kind of semigroup, as they also have an identity value.
1514+
This is because monoids are a special kind of semigroup, as in addition to the associative operation they also have a matching identity value.
15151515

15161516
The first function is `mempty`.
15171517
It's not really a function, since it doesn't take parameters, so it's a polymorphic constant, kind of like `minBound` from `Bounded`.
@@ -1533,16 +1533,16 @@ The reason `mconcat` is there at all is because for some instances, there might
15331533

15341534
Before moving on to specific instances of `Monoid`, let's take a brief look at the semigroup and monoid laws.
15351535
We mentioned that there has to be a value that acts as the identity with respect to the binary function and that the binary function has to be associative.
1536-
It's possible to make instances of `Semigroup` and `Monoid` that don't follow these rules, but such instances are of no use to anyone because when using the `Monoid` type class, we rely on its instances acting like monoids.
1536+
It's possible to make instances that don't follow these rules, but such instances are of no use to anyone because when using the `Monoid` type class, we rely on its instances acting like monoids.
15371537
Otherwise, what's the point?
15381538
That's why when making instances, we have to make sure they follow these laws:
15391539

15401540
* `(x <> y) <> z = x <> (y <> z)`{.label .law} (semigroup law)
15411541
* `mempty <> x = x`{.label .law} (monoid law)
15421542
* `x <> mempty = x`{.label .law} (monoid law)
15431543

1544-
The first says that `<>` has to be associative i.e. that the order in which we use `<>` to reduce several semigroup values into one doesn't matter, and the other two state that `mempty` has to act as the identity with respect to `<>`.
1545-
Semigroups follow the first law, but monoids must follow all three.
1544+
The first says that `<>` has to be associative i.e. that the order in which we use `<>` to reduce several values into one doesn't matter, and the other two state that `mempty` has to act as the identity with respect to `<>`.
1545+
Semigroups follow the first law, but monoids follow all three.
15461546
Haskell doesn't enforce these laws, so we as the programmer have to be careful that our instances do indeed obey them.
15471547

15481548
### Lists are monoids
@@ -1903,7 +1903,7 @@ ghci> Just (Sum 3) <> Just (Sum 4)
19031903
Just (Sum {getSum = 7})
19041904
```
19051905

1906-
This comes in use when you're dealing with semigroups as results of computations that may have failed.
1906+
This comes in handy when you're dealing with semigroups as results of computations that may have failed.
19071907
Because of this instance, we don't have to check if the computations have failed by seeing if they're a `Nothing` or `Just` value; we can just continue to treat them as normal semigroups.
19081908

19091909
But what if the type of the contents of the `Maybe` aren't an instance of `Semigroup`?

0 commit comments

Comments
 (0)