You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source_md/making-our-own-types-and-typeclasses.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1041,21 +1041,19 @@ First off, we notice a new syntactic construct, the fixity declarations.
1041
1041
When we define functions as operators, we can use that to give them a fixity (but we don't have to).
1042
1042
A fixity states how tightly the operator binds and whether it's left-associative or right-associative.
1043
1043
For instance, `*`'s fixity is `infixl 7 *` and `+`'s fixity is `infixl 6`.
1044
-
That means that they're both left-associative (`4 * 3 * 2`is`(4 * 3) * 2`) but `*` binds tighter than `+`, because it has a greater fixity, so `5 * 4 + 3`is `(5 * 4) + 3`.
1044
+
That means that they're both left-associative (`4 * 3 * 2`means`(4 * 3) * 2`) but `*` binds tighter than `+`, because it has a greater fixity, so `5 + 4 * 3`means `5 + (4 * 3)`.
1045
1045
1046
1046
Otherwise, we just wrote `a :-: (List a)` instead of `Cons a (List a)`.
1047
1047
Now, we can write out lists in our list type like so:
1048
1048
1049
1049
```{.haskell:hs}
1050
1050
ghci> 3 :-: 4 :-: 5 :-: Empty
1051
-
(:-:) 3 ((:-:) 4 ((:-:) 5 Empty))
1051
+
3 :-: (4 :-: (5 :-: Empty))
1052
1052
ghci> let a = 3 :-: 4 :-: 5 :-: Empty
1053
1053
ghci> 100 :-: a
1054
-
(:-:) 100 ((:-:) 3 ((:-:) 4 ((:-:) 5 Empty)))
1054
+
100 :-: (3 :-: (4 :-: (5 :-: Empty)))
1055
1055
```
1056
1056
1057
-
When deriving `Show` for our type, Haskell will still display it as if the constructor was a prefix function, hence the parentheses around the operator (remember, `4 + 3` is `(+) 4 3`).
1058
-
1059
1057
Let's make a function that adds two of our lists together.
1060
1058
This is how `++` is defined for normal lists:
1061
1059
@@ -1082,7 +1080,7 @@ And let's see if it works ...
0 commit comments