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
Operator alias declarations are made up of four parts:
378
+
*Types* can also serve as operators. Consider this example from the module `Data.Tuple.Nested` of `purescript-tuples`:
379
+
```purescript
380
+
infixr 6 type Tuple as /\
381
+
```
382
+
383
+
Operator alias declarations are made up of five parts:
379
384
380
385
* The associativity: either `infixl`, `infixr`, or `infix`.
381
386
* The precedence: an integer, between 0 and 9. Here, it is 5.
387
+
* The `type` keyword, if the symbol to be aliased is a type constructor.
382
388
* The function to alias: here, `append`
383
389
* The operator: here, `<>`.
384
390
385
391
The declaration determines how expressions involving this operator are bracketed.
386
392
393
+
### Qualified operators
394
+
395
+
Operators can be imported from other modules in their qualified form. For example:
396
+
397
+
```purescript
398
+
import Data.Tuple as Tuple
399
+
400
+
tuple :: Int Tuple./\ Int Tuple./\ Int
401
+
tuple = 1 Tuple./\ 2 Tuple./\ 3
402
+
```
403
+
387
404
### Associativity
388
405
389
406
`infixl` means that repeated applications are bracketed starting from the left. For example, `#` from Prelude is left-associative, meaning that an expression such as:
@@ -476,6 +493,11 @@ Operators can be used as normal values by surrounding them with parentheses:
476
493
and = (&&)
477
494
```
478
495
496
+
For qualified operators, enclosing parentheses come *after* the qualifying module:
497
+
```purescript
498
+
and = Data.HeytingAlgebra.(&&)
499
+
```
500
+
479
501
### Operator sections
480
502
481
503
Operators can be partially applied by surrounding them with parentheses and using `_` as one of the operands:
0 commit comments