2014-05-21 18:24:24 +00:00
|
|
|
local env = bare_environment()
|
2014-05-12 21:51:18 +00:00
|
|
|
local l_name = name("l")
|
|
|
|
local l = mk_param_univ(l_name)
|
|
|
|
local U_l = mk_sort(l)
|
|
|
|
local x = Const("x")
|
2014-06-30 16:14:55 +00:00
|
|
|
local A = Local("A", U_l)
|
|
|
|
local x = Local("x", A)
|
2014-05-12 21:51:18 +00:00
|
|
|
local A2A = mk_arrow(A, A)
|
2014-06-30 16:14:55 +00:00
|
|
|
local id_ty = Pi(A, mk_arrow(A, A))
|
|
|
|
local id_def = Fun(A, Fun(x, x))
|
2014-05-12 21:51:18 +00:00
|
|
|
env = add_decl(env, mk_definition(env, "id", {l_name}, id_ty, id_def, {opaque=false}))
|
|
|
|
local ok, ex = pcall(function()
|
|
|
|
env = add_decl(env, mk_definition(env, "id2", {"l2"}, id_ty, id_def, {opaque=false}))
|
|
|
|
end
|
|
|
|
)
|
|
|
|
assert(not ok)
|
|
|
|
print(ex:what())
|
|
|
|
local tc = type_checker(env)
|
|
|
|
local ok, ex = pcall(function()
|
|
|
|
local id = Const("id")
|
|
|
|
tc:check(id)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
assert(not ok)
|
|
|
|
print(ex:what())
|
|
|
|
local id_1 = Const("id", {mk_level_one()})
|
|
|
|
print(tc:check(id_1))
|
|
|
|
assert(not pcall(function()
|
|
|
|
id_u = Const("id", {mk_global_univ("u")})
|
|
|
|
print(tc:check(id_u))
|
|
|
|
end
|
|
|
|
))
|
|
|
|
assert(not pcall(function()
|
|
|
|
id_1_1 = Const("id", {mk_level_one(), mk_level_one()})
|
|
|
|
print(tc:check(id_1_1))
|
|
|
|
end
|
|
|
|
))
|
2014-06-13 15:26:05 +00:00
|
|
|
local env2 = env:add_universe("u")
|
2014-05-12 21:51:18 +00:00
|
|
|
assert(env2:is_descendant(env))
|
|
|
|
assert(not env:is_descendant(env2))
|
|
|
|
local tc2 = type_checker(env2)
|
|
|
|
id_u = Const("id", {mk_global_univ("u")})
|
|
|
|
print(tc2:check(id_u))
|
2014-08-20 05:31:26 +00:00
|
|
|
local tmp = tc2:check(id_u)
|
|
|
|
print(tc2:check(tmp))
|
|
|
|
local tmp1 = tc2:check(id_u)
|
|
|
|
local tmp2 = tc2:check(tmp1)
|
|
|
|
print(tc2:check(tmp2))
|
2014-05-12 21:51:18 +00:00
|
|
|
env2 = add_decl(env2, mk_var_decl("a", Type))
|
|
|
|
local tc2 = type_checker(env2)
|
|
|
|
local a = Const("a")
|
|
|
|
local id_2 = Const("id", {mk_level_succ(mk_level_one())})
|
|
|
|
print(tc2:check(id_2(Type, a)))
|
|
|
|
assert(tc2:check(id_2(Type, a)) == Type)
|
|
|
|
assert(not pcall(function() print(tc2:check(id_1(Type, a))) end))
|
|
|
|
assert(tc2:whnf(id_2(Type, a)) == a)
|
|
|
|
assert(tc2:whnf(id_2(Type, id_2(Type, a))) == a)
|
|
|
|
local tc3 = type_checker(env, name_generator("foo"), {extra_opaque=name_set("id")})
|
2014-09-18 01:25:15 +00:00
|
|
|
print(tc3:whnf(id_2(Type, id_2(Type, a))))
|
2014-05-12 21:51:18 +00:00
|
|
|
assert(tc3:whnf(id_2(Type, id_2(Type, a))) == id_2(Type, id_2(Type, a)))
|
|
|
|
print(id_2(Type, id_2(Type, a)))
|