94 lines
2.1 KiB
Plaintext
94 lines
2.1 KiB
Plaintext
module Zoo4
|
|
|
|
id : {A : U} -> A -> A
|
|
id = \x => x -- elaborated to \{A} x. x
|
|
|
|
-- implicit arg types can be omitted
|
|
const : {A B} -> A -> B -> A
|
|
const = \x y => x
|
|
|
|
-- function arguments can be grouped:
|
|
group1 : {A B : U}(x y z : A) -> B -> B
|
|
group1 = \x y z b => b
|
|
|
|
group2 : {A B}(x y z : A) -> B -> B
|
|
group2 = \x y z b=> b
|
|
|
|
-- explicit id function used for annotation as in Idris
|
|
the : (A : _) -> A -> A
|
|
the = \_ x => x
|
|
|
|
-- implicit args can be explicitly given
|
|
-- NB kovacs left off the type (different syntax), so I put a hole in there
|
|
argTest1 : _
|
|
argTest1 = const {U} {U} U
|
|
|
|
-- I've decided not to do = in the {} for now.
|
|
-- let argTest2 = const {B = U} U; -- only give B, the second implicit arg
|
|
|
|
-- again no type, this hits a lambda in infer.
|
|
-- I think we need to create two metas and make a pi of them.
|
|
insert2 : _
|
|
insert2 = (\{A} x => the A x) U -- (\{A} x => the A x) {U} U
|
|
|
|
Bool : U
|
|
Bool = (B : _) -> B -> B -> B
|
|
|
|
true : Bool
|
|
true = \B t f => t
|
|
|
|
false : Bool
|
|
false = \B t f => f
|
|
|
|
List : U -> U
|
|
List = \A => (L : _) -> (A -> L -> L) -> L -> L
|
|
|
|
nil : {A} -> List A
|
|
nil = \L cons nil => nil
|
|
|
|
cons : {A} -> A -> List A -> List A
|
|
cons = \ x xs L cons nil => cons x (xs L cons nil)
|
|
|
|
map : {A B} -> (A -> B) -> List A -> List B
|
|
map = \{A} {B} f xs L c n => xs L (\a => c (f a)) n
|
|
|
|
list1 : List Bool
|
|
list1 = cons true (cons false (cons true nil))
|
|
|
|
-- dependent function composition
|
|
comp : {A} {B : A -> U} {C : {a} -> B a -> U}
|
|
(f : {a} (b : B a) -> C b)
|
|
(g : (a : A) -> B a)
|
|
(a : A)
|
|
-> C (g a)
|
|
comp = \f g a => f (g a)
|
|
|
|
compExample : _
|
|
compExample = comp (cons true) (cons false) nil
|
|
|
|
Nat : U
|
|
Nat = (N : U) -> (N -> N) -> N -> N
|
|
|
|
-- TODO - first underscore there, why are there two metas?
|
|
mul : Nat -> Nat -> Nat
|
|
mul = \a b N s z => a _ (b _ s) z
|
|
|
|
ten : Nat
|
|
ten = \N s z => (s (s (s (s (s (s (s (s (s (s z))))))))))
|
|
|
|
hundred : _
|
|
hundred = mul ten ten
|
|
|
|
-- Leibniz equality
|
|
Eq : {A} -> A -> A -> U
|
|
Eq = \{A} x y => (P : A -> U) -> P x -> P y
|
|
|
|
refl : {A} {x : A} -> Eq x x
|
|
refl = \_ px => px
|
|
|
|
sym : {A x y} -> Eq {A} x y -> Eq y x
|
|
sym = \p => p (\y => Eq y x) refl
|
|
|
|
eqtest : Eq (mul ten ten) hundred
|
|
eqtest = refl
|