mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-09-19 04:37:28 +03:00
141 lines
3.8 KiB
Plaintext
141 lines
3.8 KiB
Plaintext
// Bool
|
|
// ----
|
|
|
|
Bool : Type
|
|
True : Bool
|
|
False : Bool
|
|
|
|
Bool.not (a: Bool) : Bool
|
|
Bool.not True = False
|
|
Bool.not False = True
|
|
|
|
Bool.and (a: Bool) (b: Bool) : Bool
|
|
Bool.and True True = True
|
|
Bool.and True False = False
|
|
Bool.and False True = False
|
|
Bool.and False False = False
|
|
|
|
Bool.not_not_theorem (a: Bool) : (Equal Bool a (Bool.not (Bool.not a)))
|
|
Bool.not_not_theorem True = (Refl Bool True)
|
|
Bool.not_not_theorem False = (Refl Bool False)
|
|
|
|
// Nat
|
|
// ---
|
|
|
|
Nat : Type
|
|
Zero : Nat
|
|
Succ (pred: Nat) : Nat
|
|
|
|
Nat.double (x: Nat) : Nat
|
|
Nat.double (Succ x) = (Succ (Succ (Nat.double x)))
|
|
Nat.double (Zero) = (Zero)
|
|
|
|
Nat.add (a: Nat) (b: Nat) : Nat
|
|
Nat.add (Succ a) b = (Succ (Nat.add a b))
|
|
Nat.add Zero b = b
|
|
|
|
Nat.comm.a (a: Nat) : (Equal Nat a (Nat.add a Zero))
|
|
Nat.comm.a Zero = Refl
|
|
Nat.comm.a (Succ a) = (Equal.apply @x(Succ x) (Nat.comm.a a))
|
|
|
|
Nat.comm.b (a: Nat) (b: Nat): (Equal Nat (Nat.add a (Succ b)) (Succ (Nat.add a b)))
|
|
Nat.comm.b Zero b = Refl
|
|
Nat.comm.b (Succ a) b = (Equal.apply @x(Succ x) (Nat.comm.b a b))
|
|
|
|
Nat.comm (a: Nat) (b: Nat) : (Equal Nat (Nat.add a b) (Nat.add b a))
|
|
Nat.comm Zero b = (Nat.comm.a b)
|
|
Nat.comm (Succ a) b =
|
|
let e0 = (Equal.apply @x(Succ x) (Nat.comm a b))
|
|
let e1 = (Equal.mirror (Nat.comm.b b a))
|
|
(Equal.chain e0 e1)
|
|
|
|
Nat.to_u60 (n: Nat) : U60
|
|
Nat.to_u60 Zero = #0
|
|
Nat.to_u60 (Succ n) = (+ #1 (Nat.to_u60 n))
|
|
|
|
// List
|
|
// ----
|
|
|
|
List (a: Type) : Type
|
|
List.nil <a> : (List a)
|
|
List.cons <a> (x: a) (xs: (List a)) : (List a)
|
|
|
|
List.negate (xs: (List Bool)) : (List Bool)
|
|
List.negate (List.cons Bool x xs) = (List.cons Bool (Bool.not x) (List.negate xs))
|
|
List.negate (List.nil Bool) = (List.nil Bool)
|
|
|
|
List.tail <a> (xs: (List a)) : (List a)
|
|
List.tail a (List.cons t x xs) = xs
|
|
|
|
List.map <a> <b> (x: (List a)) (f: (x: a) b) : (List b)
|
|
List.map a b (List.nil t) f = List.nil
|
|
List.map a b (List.cons t x xs) f = (List.cons (f x) (List.map xs f))
|
|
|
|
List.concat <a> (xs: (List a)) (ys: (List a)) : (List a)
|
|
List.concat a (List.cons u x xs) ys = (List.cons u x (List.concat a xs ys))
|
|
List.concat a (List.nil u) ys = ys
|
|
|
|
List.flatten <a> (xs: (List (List a))) : (List a)
|
|
List.flatten a (List.cons u x xs) = (List.concat x (List.flatten xs))
|
|
List.flatten a (List.nil u) = List.nil
|
|
|
|
List.bind <a: Type> <b: Type> (xs: (List a)) (f: a -> (List b)) : (List b)
|
|
List.bind a b xs f = (List.flatten b (List.map xs f))
|
|
|
|
List.pure <t: Type> (x: t) : (List t)
|
|
List.pure t x = (List.cons t x (List.nil t))
|
|
|
|
List.range.go (lim: Nat) (res: (List Nat)) : (List Nat)
|
|
List.range.go Zero res = res
|
|
List.range.go (Succ n) res = (List.range.go n (List.cons n res))
|
|
|
|
List.sum (xs: (List Nat)) : Nat
|
|
List.sum (List.nil t) = Zero
|
|
List.sum (List.cons t x xs) = (Nat.add x (List.sum xs))
|
|
|
|
// Equal
|
|
// -----
|
|
|
|
Equal <t> (a: t) (b: t) : Type
|
|
Refl <t> <a: t> : (Equal t a a)
|
|
|
|
Equal.mirror <t> <a: t> <b: t> (e: (Equal t a b)) : (Equal t b a)
|
|
Equal.mirror t a b (Refl u k) = (Refl u k)
|
|
|
|
Equal.apply <t> <u> <a: t> <b: t> (f: t -> t) (e: (Equal t a b)) : (Equal t (f a) (f b))
|
|
Equal.apply t u a b f (Refl v k) = (Refl v (f k))
|
|
|
|
Equal.rewrite <t> (a: t) (b: t) (e: (Equal t a b)) (p: t -> Type) (x: (p a)) : (p b)
|
|
Equal.rewrite t a b (Refl u k) p x = {x :: (p k)}
|
|
|
|
Equal.chain <t> <a: t> <b: t> <c: t> (e0: (Equal t a b)) (e1: (Equal t b c)) : (Equal t a c)
|
|
Equal.chain t a b c e0 (Refl u x) = {e0 :: (Equal t a x)}
|
|
|
|
// Monad
|
|
// -----
|
|
|
|
Monad (f: Type -> Type) : Type
|
|
Monad.new (f: Type -> Type)
|
|
(pure: (a: Type) (x: a) (Monad (f a)))
|
|
(bind: (a: Type) (b: Type) (x: (Monad a)) (y: a -> (Monad b)) (Monad b))
|
|
: (Monad f)
|
|
|
|
// Examples
|
|
// --------
|
|
|
|
The (x: U60) : Type
|
|
Val (x: U60) : (The x)
|
|
|
|
// FIXME: won't work til HVM's flattening update
|
|
U60.to_nat (x: U60) : Nat
|
|
U60.to_nat #0 = Zero
|
|
U60.to_nat n = (Succ (U60.to_nat (- n #1)))
|
|
|
|
Main : (List (List U60)) {
|
|
do List {
|
|
ask x = [ #1, #2, #3]
|
|
ask y = [#10, #20, #30]
|
|
return [x, y]
|
|
}
|
|
}
|