2022-02-16 17:18:08 +03:00
|
|
|
module InfixErrorP;
|
|
|
|
|
User-friendly operator declaration syntax (#2270)
* Closes #1964
Adds the possibility to define operator fixities. They live in a
separate namespace. Standard library defines a few in
`Stdlib.Data.Fixity`:
```
syntax fixity rapp {arity: binary, assoc: right};
syntax fixity lapp {arity: binary, assoc: left, same: rapp};
syntax fixity seq {arity: binary, assoc: left, above: [lapp]};
syntax fixity functor {arity: binary, assoc: right};
syntax fixity logical {arity: binary, assoc: right, above: [seq]};
syntax fixity comparison {arity: binary, assoc: none, above: [logical]};
syntax fixity pair {arity: binary, assoc: right};
syntax fixity cons {arity: binary, assoc: right, above: [pair]};
syntax fixity step {arity: binary, assoc: right};
syntax fixity range {arity: binary, assoc: right, above: [step]};
syntax fixity additive {arity: binary, assoc: left, above: [comparison, range, cons]};
syntax fixity multiplicative {arity: binary, assoc: left, above: [additive]};
syntax fixity composition {arity: binary, assoc: right, above: [multiplicative]};
```
The fixities are identifiers in a separate namespace (different from
symbol and module namespaces). They can be exported/imported and then
used in operator declarations:
```
import Stdlib.Data.Fixity open;
syntax operator && logical;
syntax operator || logical;
syntax operator + additive;
syntax operator * multiplicative;
```
2023-08-09 19:15:51 +03:00
|
|
|
syntax fixity pair {arity: binary};
|
|
|
|
|
|
|
|
syntax operator , pair;
|
2022-02-16 17:18:08 +03:00
|
|
|
|
2023-01-03 15:49:04 +03:00
|
|
|
type Pair :=
|
|
|
|
, : Type → Type → Pair;
|
2022-02-16 17:18:08 +03:00
|
|
|
|
2023-08-24 12:20:09 +03:00
|
|
|
fst : Pair → Type
|
|
|
|
| (x , ) := x;
|
2022-02-16 17:18:08 +03:00
|
|
|
|
2022-04-04 18:44:08 +03:00
|
|
|
end;
|