Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aba17dc

Browse files
Add documentation for qualified operators and type operators (#462)
1 parent 7edec9f commit aba17dc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

‎language/Syntax.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,32 @@ fourToSix = Cons 4 (Cons 5 (Cons 6 Nil))
375375
oneToSix = oneToThree <> fourToSix
376376
```
377377

378-
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:
379384

380385
* The associativity: either `infixl`, `infixr`, or `infix`.
381386
* 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.
382388
* The function to alias: here, `append`
383389
* The operator: here, `<>`.
384390

385391
The declaration determines how expressions involving this operator are bracketed.
386392

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+
387404
### Associativity
388405

389406
`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:
476493
and = (&&)
477494
```
478495

496+
For qualified operators, enclosing parentheses come *after* the qualifying module:
497+
```purescript
498+
and = Data.HeytingAlgebra.(&&)
499+
```
500+
479501
### Operator sections
480502

481503
Operators can be partially applied by surrounding them with parentheses and using `_` as one of the operands:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /