Skip to content

Commit bba8a33

Browse files
committed
fixity explanation: clarify & update
1 parent 50d8eb7 commit bba8a33

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

source_md/making-our-own-types-and-typeclasses.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,21 +1041,19 @@ First off, we notice a new syntactic construct, the fixity declarations.
10411041
When we define functions as operators, we can use that to give them a fixity (but we don't have to).
10421042
A fixity states how tightly the operator binds and whether it's left-associative or right-associative.
10431043
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)`.
10451045

10461046
Otherwise, we just wrote `a :-: (List a)` instead of `Cons a (List a)`.
10471047
Now, we can write out lists in our list type like so:
10481048

10491049
```{.haskell:hs}
10501050
ghci> 3 :-: 4 :-: 5 :-: Empty
1051-
(:-:) 3 ((:-:) 4 ((:-:) 5 Empty))
1051+
3 :-: (4 :-: (5 :-: Empty))
10521052
ghci> let a = 3 :-: 4 :-: 5 :-: Empty
10531053
ghci> 100 :-: a
1054-
(:-:) 100 ((:-:) 3 ((:-:) 4 ((:-:) 5 Empty)))
1054+
100 :-: (3 :-: (4 :-: (5 :-: Empty)))
10551055
```
10561056

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-
10591057
Let's make a function that adds two of our lists together.
10601058
This is how `++` is defined for normal lists:
10611059

@@ -1082,7 +1080,7 @@ And let's see if it works ...
10821080
ghci> let a = 3 :-: 4 :-: 5 :-: Empty
10831081
ghci> let b = 6 :-: 7 :-: Empty
10841082
ghci> a .++ b
1085-
(:-:) 3 ((:-:) 4 ((:-:) 5 ((:-:) 6 ((:-:) 7 Empty))))
1083+
3 :-: (4 :-: (5 :-: (6 :-: (7 :-: Empty))))
10861084
```
10871085

10881086
Nice.

0 commit comments

Comments
 (0)