1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 06:23:13 +03:00
juvix/tests/positive/Symbols.juvix
Łukasz Czajka eebe961321
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 18:15:51 +02:00

32 lines
550 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Symbols;
import Stdlib.Data.Fixity open;
import Stdlib.Data.Nat open;
╘⑽╛ : Nat := suc 9;
-- no - function!?
- : Nat -> Nat -> Nat := (+);
- : Nat -> Nat -> Nat := (-);
* : Nat -> Nat -> Nat := (*);
syntax operator additive;
: Nat -> Nat -> Nat := -;
syntax operator · multiplicative;
· : Nat -> Nat -> Nat := *;
0 : Nat := ╘⑽╛ ╘⑽╛ · zero;
主功能 : Nat := 0;
axiom = : Type;
K : Nat → Nat → Nat
| =a@zero =b := =a · =b
| =a@(suc =b) == := =b · ==;