lean2/tests/lua/coe5.lua
Leonardo de Moura edcbe6fe10 feat(frontends/lean): allow multiple coercions from class A to B, closes #187
See new tests (for examples)
tests/lean/run/coe10.lean
tests/lean/run/coe11.lean
tests/lean/run/coe9.lean

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2014-09-14 12:59:43 -07:00

31 lines
1.5 KiB
Lua

local env = environment()
local l = param_univ("l")
env = add_decl(env, mk_var_decl("group", {l}, mk_sort(l+1)))
env = add_decl(env, mk_var_decl("abelian_group", {l}, mk_sort(l+1)))
env = add_decl(env, mk_var_decl("ring", {l}, mk_sort(l+1)))
env = add_decl(env, mk_var_decl("abelian_ring", {l}, mk_sort(l+1)))
local group = Const("group", {l})
local ring = Const("ring", {l})
local ab_group = Const("abelian_group", {l})
local ab_ring = Const("abelian_ring", {l})
env = add_decl(env, mk_var_decl("carrier", {l}, mk_arrow(group, mk_sort(l))))
env = add_coercion(env, "carrier")
env = add_decl(env, mk_var_decl("ag2g", {l}, mk_arrow(ab_group, group)))
env = add_decl(env, mk_var_decl("r2g", {l}, mk_arrow(ring, group)))
env = add_decl(env, mk_var_decl("ar2r", {l}, mk_arrow(ab_ring, ring)))
env = add_decl(env, mk_var_decl("ar2ag", {l}, mk_arrow(ab_ring, ab_group)))
env = add_coercion(env, "ag2g")
env = add_coercion(env, "r2g")
env = add_coercion(env, "ar2r")
env = add_coercion(env, "ar2ag")
for_each_coercion_sort(env, function(C, f) print(tostring(C) .. " >-> sort : " .. tostring(f)) end)
for_each_coercion_user(env, function(C, D, f) print(tostring(C) .. " >-> " .. tostring(D) .. " : " .. tostring(f)) end)
print(get_coercions_to_sort(env, Const("abelian_ring", {1})):head())
assert(env:type_check(get_coercions_to_sort(env, Const("abelian_ring", {1})):head()))
print("Coercions (abelian ring): ")
cs = get_user_coercions(env, ab_ring)
for i = 1, #cs do
print(tostring(cs[i][1]) .. " : " .. tostring(cs[i][3]) .. " : " .. tostring(cs[i][2]))
end