Skip to content

Commit b431d2b

Browse files
committed
First argument can be another structure
1 parent ccd9a32 commit b431d2b

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

HB/howto.elpi

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ pred main-str i:string, i:string, i:int.
1010
main-str S STgt Depth :- coq.locate S GR, main-gref GR STgt Depth.
1111

1212
pred main-gref i:gref, i:string, i:int.
13+
main-gref GR STgt Depth :- class-def (class _ GR _), !,
14+
private.mixins-in-structures [GR] MLSrc,
15+
main-from MLSrc STgt Depth.
1316
main-gref GR STgt Depth :-
14-
private.mixins-on-gref GR MLSrc,
17+
private.structures-on-gref GR SL,
18+
private.mixins-in-structures SL MLSrc,
1519
main-from MLSrc STgt Depth.
1620

1721
pred main-from i:list mixinname, i:string, i:int.
1822
main-from MLSrc STgt Depth :-
19-
private.mixins-in-string STgt MLTgt,
23+
private.mixins-in-structures [{coq.locate STgt}] MLTgt,
2024
private.list-diff MLTgt MLSrc ML,
2125
if (ML = []) (coq.say "HB: nothing to do.")
2226
(private.paths-from-for-step MLSrc ML Depth R,
@@ -59,20 +63,19 @@ lexi-order [] [].
5963
lexi-order [X1|_] [X2|_] :- lt-gref X1 X2.
6064
lexi-order [X|T1] [X|T2] :- lexi-order T1 T2.
6165

62-
% [mixins-on-gref GR ML] list mixins in structures [GR] is equipped with
63-
pred mixins-on-gref i:gref, o:list mixinname.
64-
mixins-on-gref GR ML :-
66+
% [structures-on-gref GR ML] list structures [GR] is equipped with
67+
pred structures-on-gref i:gref, o:list structure.
68+
structures-on-gref GR SL :-
6569
std.filter {coq.CS.db-for _ (cs-gref GR)} (about.not1 about.unif-hint?) LV,
66-
std.fold LV [] mixins-on-gref.aux ML.
67-
mixins-on-gref.aux (cs-instance _ _ GR) L L' :-
68-
coq.prod-tgt->gref {coq.env.typeof GR} F,
69-
class-def (class _ F MLWP),
70-
union L {list-w-params_list MLWP} L'.
71-
72-
% [mixins-in-string S ML] list mixins contained in structure [S]
73-
pred mixins-in-string i:string, o:list mixinname.
74-
mixins-in-string S ML :-
75-
coq.locate S GR, class-def (class _ GR MLwP), list-w-params_list MLwP ML.
70+
std.map LV structures-on-gref.aux SL.
71+
structures-on-gref.aux (cs-instance _ _ GR) F :-
72+
coq.prod-tgt->gref {coq.env.typeof GR} F, class-def (class _ F _).
73+
74+
% [mixins-in-structures SL ML] list mixins in structures [SL]
75+
pred mixins-in-structures i:list structure, o:list mixinname.
76+
mixins-in-structures SL ML :- std.fold SL [] mixins-in-structures.aux ML.
77+
mixins-in-structures.aux F L L' :-
78+
class-def (class _ F MLWP), union L {list-w-params_list MLWP} L'.
7679

7780
% a type to store a factory along with the mixins it depends on
7881
% and the mixins it provides

structures.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ Elpi Export HB.about.
305305
is the maximum length of the sequences, 3 by default.
306306
The first argument [T] is optional, when ommited [Foo.type] is built
307307
from scratch.
308+
Finally, the first argument can be another structure [Bar.type],
309+
in which case [Foo.type] is built starting from [Bar.type].
308310
*)
309311

310312
#[arguments(raw)] Elpi Command HB.howto.
@@ -332,7 +334,9 @@ main [str STgt] :- !,
332334
main [str STgt, int Depth] :- !,
333335
with-attributes (with-logging (howto.main-from [] STgt Depth)).
334336

335-
main _ :- coq.error "Usage: HB.howto [(<type>)] <structure> [<search depth>].".
337+
main _ :-
338+
coq.error
339+
"Usage: HB.howto [(<type>)|<structure>] <structure> [<search depth>].".
336340
}}.
337341
Elpi Typecheck.
338342
Elpi Export HB.howto.

tests/howto.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ HB.howto Z Ring.type 2.
1212

1313
Fail HB.howto Z Ring.type 0.
1414

15+
HB.howto AddComoid.type Ring.type.
16+
1517
HB.instance
1618
Definition _ :=
1719
AddAG_of_TYPE.Build Z 0%Z Z.add Z.opp
1820
Z.add_assoc Z.add_comm Z.add_0_l Z.add_opp_diag_l.
1921

2022
HB.howto Z Ring.type.
2123

24+
HB.howto AddAG.type Ring.type.
25+
2226
HB.instance
2327
Definition _ :=
2428
Ring_of_TYPE.Build Z 0%Z 1%Z Z.add Z.opp Z.mul

tests/howto.v.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ HB: solutions (use 'HB.about F.Build' to see the arguments of each factory F):
4040

4141
The command has indeed failed with message:
4242
HB: no solution found, try to increase search depth.
43+
HB: solutions (use 'HB.about F.Build' to see the arguments of each factory F):
44+
- Ring_of_AddComoid
45+
- AddAG_of_AddComoid; BiNearRing_of_AddMonoid
46+
- AddAG_of_AddComoid; Ring_of_AddAG
47+
- AddAG_of_AddComoid; SemiRing_of_AddComoid
48+
- BiNearRing_of_AddMonoid; AddAG_of_AddComoid
49+
- SemiRing_of_AddComoid; AddAG_of_AddComoid
50+
51+
HB: solutions (use 'HB.about F.Build' to see the arguments of each factory F):
52+
- BiNearRing_of_AddMonoid
53+
- Ring_of_AddAG
54+
- SemiRing_of_AddComoid
55+
4356
HB: solutions (use 'HB.about F.Build' to see the arguments of each factory F):
4457
- BiNearRing_of_AddMonoid
4558
- Ring_of_AddAG

0 commit comments

Comments
 (0)