33 lines
572 B
Markdown
33 lines
572 B
Markdown
# Infix Operators
|
|
|
|
Example of defining `->` to do `map` for any functor:
|
|
|
|
```
|
|
given F[*] :: Functor, A, B
|
|
infix -> (fa: F[A], f: (A) => B) => F[B] :=
|
|
map (fa) (f)
|
|
```
|
|
|
|
```
|
|
let xs: List[Int] := list(1, 2, 3)
|
|
let addOne := (x: Int32) => x + 1
|
|
|
|
-- [2, 3, 4]
|
|
let ys := xs -> addOne
|
|
|
|
-- [4, 5, 6]
|
|
let zs := xs -> addOne -> addOne -> addOne
|
|
-- note, in order precedence: ((xs -> addOne) -> addOne) -> addOne
|
|
```
|
|
|
|
## Precedence
|
|
|
|
In order precedence.
|
|
|
|
## Using Parentheses to Group
|
|
|
|
Infix operators for numeric operations are defined for tuples of size one.
|
|
|
|
```
|
|
(12 - 2) / 2
|
|
```
|