2014-05-19 22:44:15 +00:00
|
|
|
local env = environment()
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
function bad_add_inductive(...)
|
|
|
|
arg = {...}
|
|
|
|
ok, msg = pcall(function() add_inductive(unpack(arg)) end)
|
|
|
|
assert(not ok)
|
|
|
|
print("\nExpected error: " .. msg:what())
|
|
|
|
end
|
|
|
|
|
|
|
|
local l = mk_param_univ("l")
|
|
|
|
local U_l = mk_sort(l)
|
2014-07-22 16:43:18 +00:00
|
|
|
local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop
|
2014-05-18 03:10:45 +00:00
|
|
|
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")
|
|
|
|
local forest_l = Const("forest", {l})
|
|
|
|
local tree_l = Const("tree", {l})
|
|
|
|
local n = Const("n")
|
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"nat", Type,
|
2014-07-22 16:43:18 +00:00
|
|
|
"zero", Prop, -- Incorrect result type
|
2014-05-18 03:10:45 +00:00
|
|
|
"succ", mk_arrow(Nat, Nat))
|
|
|
|
|
2014-06-30 16:14:55 +00:00
|
|
|
local A = Local("A", U_l)
|
|
|
|
|
2014-05-18 03:10:45 +00:00
|
|
|
bad_add_inductive(env, {l}, 1,
|
|
|
|
{"tree", mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"node", Pi(A, mk_arrow(A, forest_l(A), tree_l(A)))
|
2014-05-18 03:10:45 +00:00
|
|
|
},
|
|
|
|
{"forest", mk_arrow(U_l1, U_l1), -- Parameters of all inductive types must match
|
2014-06-30 16:14:55 +00:00
|
|
|
"emptyf", Pi(A, forest_l(A)),
|
|
|
|
"consf", Pi(A, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))})
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env, {l}, 1,
|
|
|
|
{"tree", mk_arrow(U_l, U_l), -- Result may be in universe zero (e.g., l is instantiated with zero)
|
2014-06-30 16:14:55 +00:00
|
|
|
"node", Pi(A, mk_arrow(A, forest_l(A), tree_l(A)))
|
2014-05-18 03:10:45 +00:00
|
|
|
},
|
|
|
|
{"forest", mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"emptyf", Pi(A, forest_l(A)),
|
|
|
|
"consf", Pi(A, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))})
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"nat", 1, Type, -- mismatch in the number of arguments claimed
|
|
|
|
"zero", Nat,
|
|
|
|
"succ", mk_arrow(Nat, Nat))
|
|
|
|
|
|
|
|
env = add_inductive(env,
|
|
|
|
"nat", Type,
|
|
|
|
"zero", Nat,
|
|
|
|
"succ", mk_arrow(Nat, Nat))
|
|
|
|
|
|
|
|
local Even = Const("Even")
|
|
|
|
local Odd = Const("Odd")
|
2014-06-30 16:14:55 +00:00
|
|
|
local b = Local("b", Nat)
|
2014-05-18 03:10:45 +00:00
|
|
|
bad_add_inductive(env, {},
|
|
|
|
{"Even", mk_arrow(Nat, Type),
|
|
|
|
"zero_is_even", Even(zero),
|
2014-06-30 16:14:55 +00:00
|
|
|
"succ_odd", Pi(b, mk_arrow(Odd(b), Even(succ(b))))},
|
2014-07-22 16:43:18 +00:00
|
|
|
{"Odd", mk_arrow(Nat, Prop), -- if one datatype lives in Prop, then all must live in Prop
|
2014-06-30 16:14:55 +00:00
|
|
|
"succ_even", Pi(b, mk_arrow(Even(b), Odd(succ(b))))})
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-07-22 16:43:18 +00:00
|
|
|
"nil", Pi(A, mk_arrow(mk_arrow(list_l(A), Prop), list_l(A))), -- nonpositive occurrence of inductive datatype
|
2014-06-30 16:14:55 +00:00
|
|
|
"cons", Pi(A, mk_arrow(A, list_l(A), list_l(A))))
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"nil", Pi(A, list_l(mk_arrow(A, A))),
|
|
|
|
"cons", Pi(A, mk_arrow(A, list_l(A), list_l(A))))
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
local list_1 = Const("list", {mk_level_one()})
|
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"nil", Pi(A, list_l(A)),
|
|
|
|
"cons", Pi(A, mk_arrow(A, list_1(Nat), list_l(A)))) -- all list occurrences must be of the form list_l(A)
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"nil", Pi(A, list_l(A)),
|
|
|
|
"cons", Pi(A, mk_arrow(A, list_1(A), list_1(A))))
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"nil", Pi(A, mk_arrow(U_l, list_l(A))),
|
|
|
|
"cons", Pi(A, mk_arrow(A, list_l(A), list_l(A))))
|
2014-05-18 03:10:45 +00:00
|
|
|
|
|
|
|
bad_add_inductive(env,
|
|
|
|
"list", {l}, 1, mk_arrow(U_l, U_l1),
|
2014-06-30 16:14:55 +00:00
|
|
|
"nil", Pi(A, list_l(A)),
|
|
|
|
"cons", Pi(A, mk_arrow(list_l(A), A, list_l(A))))
|
2014-05-18 03:10:45 +00:00
|
|
|
|
2014-06-30 16:14:55 +00:00
|
|
|
local A = Local("A", Type)
|
2014-07-22 16:43:18 +00:00
|
|
|
env = add_decl(env, mk_var_decl("eq", Pi(A, mk_arrow(A, A, Prop))))
|
2014-05-18 03:10:45 +00:00
|
|
|
local eq = Const("eq")
|
|
|
|
local Nat2 = Const("nat2")
|
2014-06-30 16:14:55 +00:00
|
|
|
local a = Local("a", Nat2)
|
2014-05-18 03:10:45 +00:00
|
|
|
bad_add_inductive(env,
|
|
|
|
"nat2", Type,
|
|
|
|
"zero2", Nat2,
|
2014-06-30 16:14:55 +00:00
|
|
|
"succ2", Pi(a, mk_arrow(eq(Nat2, a, a), Nat2)))
|
2014-05-19 22:44:15 +00:00
|
|
|
|
2014-05-21 18:24:24 +00:00
|
|
|
local env = bare_environment()
|
2014-05-19 22:44:15 +00:00
|
|
|
bad_add_inductive(env, -- Environment does not support inductive datatypes
|
|
|
|
"nat", Type,
|
|
|
|
"zero", Nat,
|
|
|
|
"succ", mk_arrow(Nat, Nat))
|