arliss_obsidian/fp/Language/Infix Operators/Defining.md

25 lines
358 B
Markdown
Raw Normal View History

2024-09-23 23:56:55 +00:00
[[Infix Operators|Operators]] are defined with the keyword `infix`, `infixl` or `infixr`.
```haskell
infix <precedence> <fn> as <operator>
-- or
infixl -- ..
-- or
infixr -- ..
```
e.g.
```haskell
eq :: Int -> Int -> Boolean
eq = -- ...
add :: Int -> Int -> Int
add = -- ...
infixl 2 add as +
infixl 1 eq as ==
1 + 2 == 3
-- same as
(eq (add 1 2) 3)
```