@@ -9,28 +9,58 @@ namespace tc {
99 (pi X H L Ign\ fold-map X L X [H|L] :- var X H Ign, !) =>
1010 fold-map T [] _ R.
1111
12- % [build-eta-llam-links LHS Scope Ty Names PF NPF OldLinks NewVar NewLinks]
13- % Builds the eta/llam links at runtime for a term having the shape
14- % `app[(uvar X Scope as V) | L]`.
15- % LHS should be V, Scope the scope of V, TODO: finish to document this...
12+ pred split-pf i:list term, i:list term, o:list term, o:list term.
13+ split-pf [] _ [] [] :- !.
14+ split-pf [X|Xs] Old [X|Ys] L :- name X, not (std.mem! Old X), !, split-pf Xs [X|Old] Ys L.
15+ split-pf Xs _ [] Xs.
16+
17+ % [build-eta-llam-links.aux LHS Scope Ty Names PF NPF OldLinks NewVar NewLinks]
1618 :index(_ _ _ _ 3)
17- % TODO: the argument Ty is unused, i.e. the binders of the eta links have no type...
18- % LHS Scope Ty Names PF NPF OldLinks NewVar
19- pred build-eta-llam-links i:term, i:list term, o:term, i:list term, i:list term, i:list term, i:list prop, o:term, o:list prop.
20- build-eta-llam-links LHS _ _ Names [] NPF OL HD [tc.link.llam T (app [LHS | NPF]) | OL] :- !,
19+ pred build-eta-llam-links.aux i:term, i:list term, o:term, i:list term, i:list term, i:list term, i:list prop, o:term, o:list prop.
20+ build-eta-llam-links.aux LHS _ _ Names [] NPF OL HD [llam T (app [LHS | NPF]) | OL] :- !,
2121 std.assert! (not (NPF = [])) "[TC] NPF List should not be empty",
2222 prune T Names,
2323 var T HD _.
24- build-eta-llam-links LHS SC (prod _ Ty _) _ [X] [] OL HD [tc.link. eta LHS (fun `_` Ty (x\ V x)) | OL] :- !,
24+ build-eta-llam-links.aux LHS SC (prod _ Ty _) _ [X] [] OL HD [eta LHS (fun `_` Ty (x\ V x)) | OL] :- !,
2525 prune V SC, var (V X) HD _.
26- build-eta-llam-links LHS SC (prod _ Ty Bo) Names [X|XS] NPF OL HD [tc.link. eta LHS (fun `_` Ty (x\ LHS' x)) | L] :- !,
26+ build-eta-llam-links.aux LHS SC (prod _ Ty Bo) Names [X|XS] NPF OL HD [eta LHS (fun `_` Ty (x\ LHS' x)) | L] :- !,
2727 % TODO: unfold Ty if needed...
2828 std.append SC [X] SC',
29- prune LHS' SC, build-eta-llam-links (LHS' X) SC' (Bo X) Names XS NPF OL HD L.
30- build-eta-llam-links LHS SC Ty Names ([_|_] as PF) NPF OL HD L :-
29+ prune LHS' SC, build-eta-llam-links.aux (LHS' X) SC' (Bo X) Names XS NPF OL HD L.
30+ build-eta-llam-links.aux LHS SC Ty Names ([_|_] as PF) NPF OL HD L :-
3131 Ty' = prod _ _ _, coq.unify-eq Ty Ty' ok, !,
32- build-eta-llam-links LHS SC Ty' Names PF NPF OL HD L.
33-
32+ build-eta-llam-links.aux LHS SC Ty' Names PF NPF OL HD L.
33+
34+ % [build-eta-llam-links T OldLinks X NewLinks]
35+ % T = app[(uvar _ Scope) | S] this term is problematic and asks for the
36+ % creation of eta- and/or llam-links. Below some examples:
37+
38+ % eta: when compiling t = (app [X, x, y]) and [x,y] are distinct_names, then
39+ % the coq variable has not [x,y] in scope: it is applied to them.
40+ % The solution is to build the following links:
41+ % NewLinks = [X =η (λa.Y a), a |- Y a =η (λb.Z a b)]
42+ % and the exposed variable is G, given by `var G Z [x, y]`
43+
44+ % llam: when compiling t = (app [X, a, x]) where a is a constant and x a
45+ % name, we build a llam link.
46+ % The link will be: NewLinks ] = [T x =L X a x]
47+ % and the exposed variable is G, given by `var G T [x]`
48+
49+ % eta-llam: here a combination of eta and llam:
50+ % let t = (app [X x y, z, c, w, d]) where X is a coq var with x and y
51+ % in scope, z and w are names and c, d are constants.
52+ % In this case, the links should be:
53+ % NewLinks = [X x y =η (λa.Y x y a), a |- Z x y a w =L (app[Y x y a, c w d])]
54+ % and the exposed variable is G, given by `var Z T [x, y, z, w]`
55+ pred build-eta-llam-links i:term, i:list prop, o:term, o:list prop.
56+ build-eta-llam-links (app[(uvar _ Scope as V) | S] as T) Links G NewLinks :- !,
57+ coq.typecheck V Ty ok,
58+ split-pf S Scope PF NPF,
59+ free-names T Names,
60+ build-eta-llam-links.aux V Scope Ty Names PF NPF Links LhsHd NewLinks,
61+ prune G Names,
62+ var G LhsHd Names.
63+ build-eta-llam-links T _ _ _ :- coq.error "[TC] invalid call to build-eta-llam-links:" T.
3464
3565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3666 % ETA LINK %
0 commit comments