mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +03:00
eebe961321
* 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; ```
54 lines
1009 B
Plaintext
54 lines
1009 B
Plaintext
module AsPattern;
|
||
|
||
import Stdlib.Data.Fixity open;
|
||
|
||
syntax operator ∘ composition;
|
||
|
||
∘
|
||
: {A : Type}
|
||
→ {B : Type}
|
||
→ {C : Type}
|
||
→ (B → C)
|
||
→ (A → B)
|
||
→ A
|
||
→ C
|
||
| {_} {B} {_} f g x := f (g x);
|
||
|
||
builtin nat
|
||
type Nat :=
|
||
| zero : Nat
|
||
| suc : Nat → Nat;
|
||
|
||
syntax operator + additive;
|
||
|
||
builtin nat-plus
|
||
+ : Nat → Nat → Nat
|
||
| zero b := b
|
||
| (suc a) b := suc (a + b);
|
||
|
||
syntax operator × functor;
|
||
syntax operator , pair;
|
||
type × (A : Type) (B : Type) :=
|
||
| , : A → B → A × B;
|
||
|
||
fst : {A : Type} → {B : Type} → A × B → A
|
||
| p@(a, _) := a;
|
||
|
||
snd : {A : Type} → {B : Type} → A × B → B
|
||
| p@(_, b) := b;
|
||
|
||
lambda : Nat → Nat → Nat
|
||
| x :=
|
||
λ {
|
||
a@(suc _) := a + x + zero
|
||
| zero := zero
|
||
};
|
||
|
||
a : {A : Type} → A × Nat → Nat
|
||
| {A'@_} p@(x, s@zero) := snd p + 1
|
||
| p@(x, s@_) := snd p + 1;
|
||
|
||
b : {A : Type} → A × Nat → ({B : Type} → B → B) → A
|
||
| p@(_, zero) f := (f ∘ fst) p
|
||
| p@(_, _) f := (f ∘ fst) p;
|