2023-07-10 20:57:55 +03:00
|
|
|
module Syntax;
|
|
|
|
|
|
|
|
compose {A B C : Type} (f : B -> C) (g : A -> B) (x : A)
|
|
|
|
: C := f (g x);
|
|
|
|
|
|
|
|
compose' {A B C : Type} (f : B -> C) (g : A -> B) : A -> C
|
|
|
|
| x := f (g x);
|
|
|
|
|
|
|
|
type Bool :=
|
|
|
|
| false : Bool
|
|
|
|
| true : Bool;
|
|
|
|
|
|
|
|
type Nat :=
|
|
|
|
| zero : Nat
|
|
|
|
| suc : Nat -> Nat;
|
|
|
|
|
|
|
|
not : Bool -> Bool
|
|
|
|
| false := true
|
|
|
|
| true := false;
|
|
|
|
|
|
|
|
even : Nat -> Bool
|
|
|
|
| zero := true
|
|
|
|
| (suc n) := odd n;
|
|
|
|
|
|
|
|
odd : Nat -> Bool
|
|
|
|
| zero := false
|
|
|
|
| (suc n) := even n;
|
|
|
|
|
2023-09-14 11:57:38 +03:00
|
|
|
syntax fixity cmp := binary {};
|
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 ==1 cmp;
|
2023-07-10 20:57:55 +03:00
|
|
|
|
|
|
|
==1 : Nat -> Nat -> Bool
|
|
|
|
| zero zero := true
|
|
|
|
| (suc a) (suc b) := a ==2 b
|
|
|
|
| _ _ := false;
|
|
|
|
|
|
|
|
-- note that ==2 is used before its infix definition
|
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 ==2 cmp;
|
2023-07-10 20:57:55 +03:00
|
|
|
|
|
|
|
==2 : Nat -> Nat -> Bool
|
|
|
|
| zero zero := true
|
|
|
|
| (suc a) (suc b) := a ==1 b
|
|
|
|
| _ _ := false;
|
|
|
|
|
|
|
|
module MutualTypes;
|
|
|
|
-- we use Tree and isEmpty before their definition
|
|
|
|
isNotEmpty {a : Type} (t : Tree a) : Bool :=
|
|
|
|
not (isEmpty t);
|
|
|
|
|
|
|
|
isEmpty {a : Type} : (t : Tree a) -> Bool
|
|
|
|
| empty := true
|
|
|
|
| (node _ _) := false;
|
|
|
|
|
|
|
|
type Tree (a : Type) :=
|
|
|
|
| empty : Tree a
|
|
|
|
| node : a -> Forest a -> Tree a;
|
|
|
|
|
|
|
|
type Forest (a : Type) :=
|
|
|
|
| nil : Forest a
|
|
|
|
| cons : Tree a -> Forest a;
|
|
|
|
end;
|