2014-05-18 02:30:43 +00:00
|
|
|
local env = empty_environment()
|
|
|
|
local l = mk_param_univ("l")
|
|
|
|
local A = Const("A")
|
|
|
|
local U_l = mk_sort(l)
|
|
|
|
local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Bool/Prop
|
|
|
|
local list_l = Const("list", {l}) -- list.{l}
|
|
|
|
local Nat = Const("nat")
|
|
|
|
local vec_l = Const("vec", {l}) -- vec.{l}
|
|
|
|
local zero = Const("zero")
|
|
|
|
local succ = Const("succ")
|
2014-05-17 16:25:03 +00:00
|
|
|
local forest_l = Const("forest", {l})
|
|
|
|
local tree_l = Const("tree", {l})
|
2014-05-18 02:30:43 +00:00
|
|
|
local n = Const("n")
|
|
|
|
env = add_inductive(env,
|
|
|
|
"nat", Type,
|
|
|
|
"zero", Nat,
|
|
|
|
"succ", mk_arrow(Nat, Nat))
|
|
|
|
-- In the following inductive datatype, {l} is the list of universe level parameters.
|
|
|
|
-- 1 is the number of parameters.
|
|
|
|
-- The Boolean true in {A, U_l, true} is marking that this argument is implicit.
|
2014-05-17 20:59:06 +00:00
|
|
|
env = add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
|
|
|
"nil", Pi({{A, U_l, true}}, list_l(A)),
|
|
|
|
"cons", Pi({{A, U_l, true}}, mk_arrow(A, list_l(A), list_l(A))))
|
|
|
|
env = add_inductive(env,
|
|
|
|
"vec", {l}, 1,
|
|
|
|
mk_arrow(U_l, Nat, U_l1),
|
|
|
|
"vnil", Pi({{A, U_l, true}}, vec_l(A, zero)),
|
|
|
|
"vcons", Pi({{A, U_l, true}, {n, Nat, true}}, mk_arrow(A, vec_l(A, n), vec_l(A, succ(n)))))
|
2014-05-17 16:25:03 +00:00
|
|
|
|
|
|
|
local And = Const("and")
|
|
|
|
local Or = Const("or")
|
|
|
|
local B = Const("B")
|
2014-05-18 02:30:43 +00:00
|
|
|
-- Datatype without introduction rules (aka constructors). It is a uninhabited type.
|
2014-05-17 20:59:06 +00:00
|
|
|
env = add_inductive(env, "false", Bool)
|
2014-05-18 02:30:43 +00:00
|
|
|
-- Datatype with a single constructor.
|
2014-05-17 20:59:06 +00:00
|
|
|
env = add_inductive(env, "true", Bool, "trivial", Const("true"))
|
|
|
|
env = add_inductive(env,
|
|
|
|
"and", mk_arrow(Bool, Bool, Bool),
|
|
|
|
"and_intro", Pi({{A, Bool, true}, {B, Bool, true}}, mk_arrow(A, B, And(A, B))))
|
|
|
|
env = add_inductive(env,
|
|
|
|
"or", mk_arrow(Bool, Bool, Bool),
|
|
|
|
"or_intro_left", Pi({{A, Bool, true}, {B, Bool, true}}, mk_arrow(A, Or(A, B))),
|
|
|
|
"or_intro_right", Pi({{A, Bool, true}, {B, Bool, true}}, mk_arrow(B, Or(A, B))))
|
2014-05-17 16:25:03 +00:00
|
|
|
local P = Const("P")
|
|
|
|
local a = Const("a")
|
|
|
|
local exists_l = Const("exists", {l})
|
2014-05-17 20:59:06 +00:00
|
|
|
env = add_inductive(env,
|
|
|
|
"exists", {l}, 2, Pi({{A, U_l}}, mk_arrow(mk_arrow(A, Bool), Bool)),
|
|
|
|
"exists_intro", Pi({{A, U_l, true}, {P, mk_arrow(A, Bool), true}, {a, A}}, mk_arrow(P(a), exists_l(A, P))))
|
2014-05-17 16:25:03 +00:00
|
|
|
|
2014-05-17 20:59:06 +00:00
|
|
|
env = add_inductive(env, {l}, 1,
|
|
|
|
{"tree", mk_arrow(U_l, U_l1),
|
|
|
|
"node", Pi({{A, U_l, true}}, mk_arrow(A, forest_l(A), tree_l(A)))
|
|
|
|
},
|
|
|
|
{"forest", mk_arrow(U_l, U_l1),
|
|
|
|
"emptyf", Pi({{A, U_l, true}}, forest_l(A)),
|
|
|
|
"consf", Pi({{A, U_l, true}}, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))})
|
|
|
|
|
|
|
|
local tc = type_checker(env)
|
|
|
|
print(tc:check(Const("forest", {mk_level_zero()})))
|
|
|
|
print(tc:check(Const("vcons", {mk_level_zero()})))
|
|
|
|
print(tc:check(Const("consf", {mk_level_zero()})))
|
2014-05-18 02:19:32 +00:00
|
|
|
local Even = Const("Even")
|
|
|
|
local Odd = Const("Odd")
|
|
|
|
local b = Const("b")
|
|
|
|
env = add_inductive(env, {},
|
|
|
|
{"Even", mk_arrow(Nat, Bool),
|
|
|
|
"zero_is_even", Even(zero),
|
|
|
|
"succ_odd", Pi(b, Nat, mk_arrow(Odd(b), Even(succ(b))))},
|
|
|
|
{"Odd", mk_arrow(Nat, Bool),
|
|
|
|
"succ_even", Pi(b, Nat, mk_arrow(Even(b), Odd(succ(b))))})
|
2014-05-18 03:12:55 +00:00
|
|
|
|
|
|
|
local flist_l = Const("flist", {l})
|
|
|
|
env = add_inductive(env,
|
|
|
|
"flist", {l}, 1, mk_arrow(U_l, U_l1),
|
|
|
|
"fnil", Pi({{A, U_l, true}}, flist_l(A)),
|
|
|
|
"fcons", Pi({{A, U_l, true}}, mk_arrow(A, mk_arrow(Nat, flist_l(A)), flist_l(A))))
|