2022-07-25 13:30:18 +03:00
|
|
|
module TypeAlias;
|
|
|
|
|
2023-10-31 20:36:34 +03:00
|
|
|
type T := t : T;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-10-31 20:36:34 +03:00
|
|
|
type T2 := t2 : T2;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
alias : Type := T;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
x : alias := t;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
id : Type → Type
|
|
|
|
| x := x;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-09-14 11:57:38 +03:00
|
|
|
syntax fixity composition := binary {assoc := right};
|
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 operator ⊙ composition;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
⊙ : (Type → Type) → (Type → Type) → Type → Type
|
|
|
|
| f g x := f (g x);
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
x2 : (id ⊙ id) alias := t;
|
|
|
|
|
|
|
|
flip
|
|
|
|
: (Type → Type → Type) → id Type → Type → (id ⊙ id) Type
|
|
|
|
| f a b := f b a;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-01-03 15:49:04 +03:00
|
|
|
type Pair (A : Type) (B : Type) :=
|
2023-10-31 20:36:34 +03:00
|
|
|
mkPair : id T → id (id A) → B → Pair A B;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
p : {A : Type} → A → Pair A A
|
|
|
|
| a := mkPair t a a;
|
2022-07-25 13:30:18 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
x' : flip Pair (id _) T2 := mkPair x t2 t;
|
2023-04-20 13:07:37 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
funAlias : Type -> Type
|
|
|
|
| a := a -> a;
|
2023-04-20 13:07:37 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
f : funAlias T := \ {t := t};
|
2023-04-20 13:07:37 +03:00
|
|
|
|
2023-07-11 18:22:07 +03:00
|
|
|
f' : funAlias T
|
|
|
|
| t := t;
|