Skip to content

Commit c7cbb11

Browse files
committed
Fix the join of structures with parameters
A non-obvious fix for an obvious bug
1 parent f0fda30 commit c7cbb11

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

hb.elpi

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,25 +1337,40 @@ declare-coercion SortProjection ClassProjection
13371337
coq.CS.declare-instance (const SC), % TODO: API in Elpi, take a @constant instead of gref
13381338
].
13391339

1340+
pred join-body i:int, i:int, i:term, i:term, i:term, i:term, i:term, i:term,
1341+
i:list term, i:name, i:term, i:(term -> A), o:term.
1342+
join-body N1 N2 S3 S2_Pack S1_sort S3_to_S1 S2_class S3_to_S2
1343+
P N _Ty _F (fun N S3P Pack) :- !,
1344+
mk-app S3 P S3P, !,
1345+
mk-n-holes N1 Holes1, !,
1346+
mk-n-holes N2 Holes2, !,
1347+
@pi-decl N S3P s\
1348+
sigma S3_to_S1_Ps S3_to_S2_Ps S1_sortS3Ps S2_classS3Ps \ std.do! [
1349+
mk-app S3_to_S1 {std.append P [s]} S3_to_S1_Ps,
1350+
mk-app S1_sort {std.append Holes1 [S3_to_S1_Ps]} S1_sortS3Ps,
1351+
mk-app S3_to_S2 {std.append P [s]} S3_to_S2_Ps,
1352+
mk-app S2_class {std.append Holes2 [S3_to_S2_Ps]} S2_classS3Ps ,
1353+
mk-app S2_Pack {std.append Holes2 [S1_sortS3Ps, S2_classS3Ps]} (Pack s)
1354+
].
1355+
13401356
pred declare-join i:class, i:pair class class, o:prop.
1341-
declare-join (class C3 S3 _) (pr (class C1 S1 _) (class C2 S2 _)) (join C1 C2 C3) :-
1342-
Name is {term->modname S1} ^ "_to_" ^ {term->modname S2},
1357+
declare-join (class C3 S3 MLwP3) (pr (class C1 S1 _) (class C2 S2 _)) (join C1 C2 C3) :-
1358+
Name is "join_" ^ {term->modname S3} ^
1359+
"_between_" ^ {term->modname S1} ^ "_and_" ^ {term->modname S2},
13431360

13441361
get-structure-coercion S3 S2 S3_to_S2,
13451362
get-structure-coercion S3 S1 S3_to_S1,
13461363
get-structure-sort-projection S1 S1_sort,
13471364
get-structure-class-projection S2 S2_class,
13481365
get-constructor S2 S2_Pack,
13491366

1350-
% Cyril: /!\ BUG /!\ missing parameters!
1351-
JoinBody = {{ fun s : lp:S3 =>
1352-
lp:{global S2_Pack} (lp:S1_sort (lp:S3_to_S1 s))
1353-
(lp:S2_class (lp:S3_to_S2 s)) }},
1354-
1355-
std.assert-ok! (coq.typecheck JoinBody Ty) "declare-join: JoinBody illtyped",
1367+
factory-nparams C1 N1,
1368+
factory-nparams C2 N2,
13561369

13571370
if-verbose (coq.say "HB: declare unification hint" Name),
1358-
1371+
w-params.fold MLwP3 mk-fun (join-body N1 N2 S3
1372+
(global S2_Pack) S1_sort S3_to_S1 S2_class S3_to_S2) JoinBody,
1373+
std.assert-ok! (coq.typecheck JoinBody Ty) "declare-join: JoinBody illtyped",
13591374
coq.env.add-const Name JoinBody Ty @transparent! J,
13601375
coq.CS.declare-instance (const J).
13611376

0 commit comments

Comments
 (0)