Skip to content

Commit 502ceb1

Browse files
committed
TC solver example
1 parent 2ff1697 commit 502ceb1

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

tcsolver.elpi

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
msolve L :- std.forall L (open tc).
1+
msolve L :-
2+
compile_all [{{eqdec}}] Cl,
3+
Cl => std.forall L (open tc).
24

3-
pred open i:(list prop -> term -> term -> prop), i:sealed-goal.
5+
pred open i:(term -> term -> prop), i:sealed-goal.
46
open P (nabla F) :- pi x\ open P (F x).
57
open P (seal (goal Ctx Ty Wit)) :-
68
print "TC PROBLEM:\n" Ctx "|-\n" Wit ":" Ty "\n",
7-
Ctx => P Ctx Ty Wit,
9+
Ctx => P Ty Wit,
810
print "TC INSTANCE:\n" Ctx "|-\n" Wit ":" Ty "\n".
911

1012
:index(_ 4)
11-
pred tc i:list prop, i:term, o:term.
12-
tc _ {{ eqdec bool }} {{ bool_eqdec }}.
13-
tc _ {{ eqdec nat }} {{ nat_eqdec }}.
14-
tc C {{ eqdec (pair $A $B) }} {{ pair_eqdec $A $B $FA $FB }} :-
15-
tc C (appl {{eqdec}} A) FA,
16-
tc C (appl {{eqdec}} B) FB.
13+
pred tc o:term, o:term.
1714

18-
/* brainstorm
15+
pred is_typeclass o:term.
16+
is_typeclass {{eqdec}}.
1917

20-
compile_rule_lambdapi R (pi c\ tc c (app {{eqdec}} {{bool}})).
21-
compile_rule_coq R (pi c\ tc c (app {{eqdec}} {{bool}})).
18+
pred instances o:term o:list term.
19+
instances {{eqdec}} [{{bool_eqdec}}, {{nat_eqdec}}, {{pair_eqdec}}].
2220

23-
abstract G GA,
24-
interp [R1,R2] GA PA,
25-
instantiate PA P,
26-
of P G
21+
pred compile i:term, i:list prop, i:term, o:prop.
22+
compile (prod (appl T U) F) TODO H (pi x\ C x) :-
23+
is_typeclass T,
24+
!,
25+
pi x\
26+
compile (F x) [tc (appl T U) x |TODO] (appl H x) (C x).
2727

28-
*/
28+
compile (prod _ F) TODO H (pi x\ C x) :-
29+
!,
30+
pi x\
31+
compile (F x) TODO (appl H x) (C x).
32+
33+
compile End TODO HD (tc End HD :- TODO).
34+
35+
pred compile_all i:list term, o:list prop.
36+
compile_all Refs Props :-
37+
std.map Refs instances LList,
38+
std.flatten LList Candidates,
39+
std.map Candidates
40+
(cand\claus\ sigma T\ sigma N\
41+
cand = (symb N),
42+
lp.sig N T,
43+
compile T [] cand claus)
44+
Props.

tests/OK/elpitest.lp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* dune exec lambdapi check tests/OK/elpitest.lp */
2-
32
require open tests.OK.logic;
43
require open tests.OK.bool;
54
require open tests.OK.nat;
@@ -11,8 +10,8 @@ flag "print_meta_types" on; // default is off
1110

1211
constant typeclass symbol eqdec : UTYPE;
1312
constant symbol mk_eqdec [i] :
14-
/* Π f : */ (T iT iB)
15-
/*x y : T i, (f x y = truex = y) {|and|} (x = yf x y = true)) → */
13+
Π (f : T iT iB),
14+
//(x y : T i), P ({|and|} (imp (x = y) (f x y = true))(imp (f x y = true) (x = y)))) →
1615
eqdec i;
1716

1817
symbol == [i:U] [j:eqdec i] : T iT iB;
@@ -23,7 +22,6 @@ symbol eq_bool : B → B → B ≔ λ b1 b2, bool_neg (bool_xor b1 b2);
2322
symbol Pair : UUTYPE;
2423
symbol mk_Pair [i] [j] : T iT jPair i j;
2524
symbol pair : UUU;
26-
2725
rule T (pair $i $j) ↪ Pair $i $j;
2826

2927
/* instance */ symbol bool_eqdec : eqdec boolmk_eqdec eq_bool /* p */;

0 commit comments

Comments
 (0)