Skip to content

Commit c584cf0

Browse files
authored
[Chapter 6] Fix Eq/Ord relationship (#464)
1 parent 44013c6 commit c584cf0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

text/chapter6.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ true
202202

203203
The `Ord` type class defines the `compare` function, which can be used to compare two values, for types that support ordering. The comparison operators `<` and `>` along with their non-strict companions `<=` and `>=`, can be defined in terms of `compare`.
204204

205-
_Note_: In the example below, the class signature contains `<=`. This usage of `<=` in this context indicates that Eq is a subclass of Ord and is not intended to represent the use of `<=` as a comparison operator. See the section [Superclasses](#superclasses) below.
205+
_Note_: In the example below, the class signature contains `<=`. This usage of `<=` in this context indicates that `Eq` is a superclass of `Ord` and is not intended to represent the use of `<=` as a comparison operator. See the section [Superclasses](#superclasses) below.
206206

207207
```haskell
208208
data Ordering = LT | EQ | GT
@@ -639,7 +639,7 @@ We say that one type class is a superclass of another if every instance of the s
639639

640640
We've [already seen an example of superclass relationships](#ord): the `Eq` class is a superclass of `Ord`, and the `Semigroup` class is a superclass of `Monoid`. For every type class instance of the `Ord` class, there must be a corresponding `Eq` instance for the same type. This makes sense since, in many cases, when the `compare` function reports that two values are incomparable, we often want to use the `Eq` class to determine if they are equal.
641641

642-
In general, it makes sense to define a superclass relationship when the laws for the subclass mention the superclass members. For example, for any pair of Ord and Eq instances, it is reasonable to assume that if two values are equal under the `Eq` instance, then the `compare` function should return `EQ`. In other words, `a == b` should be true exactly when `compare a b` evaluates to `EQ`. This relationship on the level of laws justifies the superclass relationship between `Eq` and `Ord`.
642+
In general, it makes sense to define a superclass relationship when the laws for the subclass mention the superclass members. For example, for any pair of `Ord` and `Eq` instances, it is reasonable to assume that if two values are equal under the `Eq` instance, then the `compare` function should return `EQ`. In other words, `a == b` should be true exactly when `compare a b` evaluates to `EQ`. This relationship on the level of laws justifies the superclass relationship between `Eq` and `Ord`.
643643

644644
Another reason to define a superclass relationship is when there is a clear "is-a" relationship between the two classes. That is, every member of the subclass _is a_ member of the superclass as well.
645645

0 commit comments

Comments
 (0)