@@ -8,9 +8,6 @@ There are instances for `Ints`, `Strings`, `Lists`, `Options`, and many more.
88Let's start by looking at a few simple types and operations
99to see what common principles we can extract.
1010
11- ==== Integer addition
12-
13-
1411Addition of `Ints` is a binary operation that is _closed_ ,
1512meaning that adding two `Ints` always produces another `Int` :
1613
@@ -28,8 +25,8 @@ that `a + 0 == 0 + a == a` for any `Int` `a`:
2825```
2926
3027There are also other properties of addition.
31- For instance, it doesn't matter in what order we add elements
32- because we always get the same result.
28+ For instance, it doesn't matter in where we place brackets when we add elements,
29+ as we always get the same result.
3330This is a property known as _associativity_ :
3431
3532```scala mdoc
@@ -39,9 +36,6 @@ This is a property known as _associativity_:
3936```
4037
4138
42- ==== Integer multiplication
43-
44-
4539The same properties for addition also apply for multiplication,
4640provided we use `1` as the identity instead of `0` :
4741
@@ -60,9 +54,6 @@ Multiplication, like addition, is associative:
6054```
6155
6256
63- ==== String and sequence concatenation
64-
65-
6657We can also add `Strings` ,
6758using string concatenation as our binary operator:
6859
@@ -146,11 +137,12 @@ is not a monoid because subtraction is not associative:
146137
147138In practice we only need to think about laws
148139when we are writing our own `Monoid` instances.
149- Unlawful instances are dangerous because
150- they can yield unpredictable results
140+ Unlawful instances are dangerous,
141+ not because using them can cause us to end up in jail,
142+ but because they can yield unpredictable results
151143when used with the rest of Cats' machinery.
152144Most of the time we can rely on the instances provided by Cats
153- and assume the library authors know what they're doing.
145+ and assume the library authors knew what they were doing.
154146
155147
156148== Definition of a Semigroup
@@ -165,6 +157,7 @@ sequence concatenation and integer addition are monoids.
165157However, if we restrict ourselves
166158to non-empty sequences and positive integers,
167159we are no longer able to define a sensible `empty` element.
160+ As a concrete example,
168161Cats has a # href (" http://typelevel.org/cats/api/cats/data/NonEmptyList.html" )[`NonEmptyList` ] data type
169162that has an implementation of `Semigroup` but no implementation of `Monoid` .
170163
@@ -214,7 +207,7 @@ object Monoid {
214207
215208# solution [
216209There are at least four monoids for `Boolean` !
217- First, we have _and_ with operator `&&` and identity `true` :
210+ First, we have *and* with operator `&&` and identity `true` :
218211
219212```scala mdoc:silent
220213given booleanAndMonoid: Monoid[Boolean] with {
@@ -223,7 +216,7 @@ given booleanAndMonoid: Monoid[Boolean] with {
223216}
224217```
225218
226- Second, we have _or_ with operator `||` and identity `false` :
219+ Second, we have *or* with operator `||` and identity `false` :
227220
228221```scala mdoc:silent
229222given booleanOrMonoid: Monoid[Boolean] with {
@@ -232,7 +225,7 @@ given booleanOrMonoid: Monoid[Boolean] with {
232225}
233226```
234227
235- Third, we have _exclusive or_ with identity `false` :
228+ Third, we have *exclusive or* with identity `false` :
236229
237230```scala mdoc:silent
238231given booleanEitherMonoid: Monoid[Boolean] with {
@@ -243,7 +236,7 @@ given booleanEitherMonoid: Monoid[Boolean] with {
243236}
244237```
245238
246- Finally, we have _exclusive nor_ (the negation of exclusive or)
239+ Finally, we have *exclusive nor* (the negation of exclusive or)
247240with identity `true` :
248241
249242```scala mdoc:silent
@@ -302,7 +295,7 @@ given setIntersectionSemigroup[A]: Semigroup[Set[A]] with {
302295```
303296
304297Set complement and set difference are not associative,
305- so they cannot be considered for either monoids or semigroups.
298+ so they cannot be either monoids or semigroups.
306299However, symmetric difference (the union less the intersection)
307300does form a monoid with the empty set:
308301
0 commit comments