Idris2-boot/sample/Vect.yaff

37 lines
995 B
Plaintext
Raw Normal View History

data Bool : Type where
False : Bool
True : Bool
data Nat : Type where
Z : Nat
S : Nat -> Nat
plus : Nat -> Nat -> Nat
plus Z $y = y
plus (S $k) $y = S (plus k y)
data Vect : Nat -> Type -> Type where
Nil : {0 a : Type} -> Vect Z a
Cons : {0 a : Type} -> {0 k : Nat} -> a -> Vect k a -> Vect (S k) a
data Env : Vect $n Type -> Type where
ENil : Env Nil
ECons : (x : $a) -> Env $xs -> Env (Cons $a $xs)
id : $a -> $a
apply : ($a -> $b) -> $a -> $b
compose : ($b -> $c) -> ($a -> $b) -> $a -> $c
zipWith : -- {0 a : _} -> {0 b : _} ->{0 c : _} -> {0 n : _} ->
($a -> $b -> $c) -> Vect $n $a -> Vect $n $b -> Vect $n $c
zipWith $f (Cons $x $xs) (Cons $y $ys) = Cons (f x y) (zipWith f xs ys)
zipWith $f Nil Nil = Nil
append : Vect $n $a -> Vect $m $a -> Vect (plus $n $m) $a
append Nil $ys = ys
append (Cons $x $xs) $ys = Cons x (append xs ys)
main : Vect (S (S (S (S Z)))) Integer
main = append (Cons 1 (Cons 2 Nil)) (Cons 3 (Cons 4 Nil))