Skip to content

Commit b085ff4

Browse files
authored
Merge pull request #73 from math-comp/instance-def
syntax HB.instance Definition := ...
2 parents 1226ab9 + 257de79 commit b085ff4

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- `HB.instance` can be applied directly to a definition as in
6+
`HB.instance Definition foo := Bar.Build T ...`
7+
- port to coq-elpi version 1.4
8+
39
## [0.9.0] - 2020-03-11
410

511
First public release for Coq 8.10 and 8.11.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ We proceed by showing that `Z` is an example of both structures, and use
5454
the lemma just proved on a statement about `Z`.
5555

5656
```coq
57-
Definition Z_CoMoid := AddComoid_of_Type.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
58-
HB.instance Z Z_CoMoid.
59-
Definition Z_AbGrp := AbelianGrp_of_AddComoid.Build Z Z.opp Z.add_opp_diag_l.
60-
HB.instance Z Z_AbGrp.
57+
HB.instance Definition Z_CoMoid := AddComoid_of_Type.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
58+
HB.instance Definition Z_AbGrp := AbelianGrp_of_AddComoid.Build Z Z.opp Z.add_opp_diag_l.
6159
6260
Lemma example2 (x : Z) : x + (- x) = - 0.
6361
Proof. by rewrite example. Qed.

hb.elpi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ declare-factory-alias Ty1 GRFS Module TheType :- std.do! [
12731273

12741274
mk-phant-mixins (global GRK) PhGRK0,
12751275
if (mixin-first-class F _) (PhGRK = PhGRK0) (append-phant-unify PhGRK0 PhGRK),
1276-
mk-phant-abbrev "Build" PhGRK _ _,
1276+
mk-phant-abbrev "Build" PhGRK BuildConst _,
12771277

12781278
std.map Hyps mixin-src_mixin ML,
12791279
main-factory-requires "axioms" (const C) ML Props SN,
@@ -1285,6 +1285,7 @@ declare-factory-alias Ty1 GRFS Module TheType :- std.do! [
12851285
% std.map {gr-deps GRK} (_\ r\ r = maximal) Implicits,
12861286
% coq.arguments.set-implicit GRK [[maximal|Implicits]] tt,
12871287
acc current (clause _ _ (factory-constructor (const C) GRK)),
1288+
acc current (clause _ _ (factory-builder-nparams BuildConst 0)),
12881289
coq.env.end-module Exports,
12891290
coq.env.end-module _Module,
12901291

@@ -1319,7 +1320,7 @@ declare-mixin-or-factory Sort1 Fields0 GRFS Module TheType D :- std.do! [
13191320
if-verbose (coq.say "HB: declare notation Axioms"),
13201321

13211322
if (D = asset-mixin) (PhGRK = PhGRK0) (append-phant-unify PhGRK0 PhGRK),
1322-
mk-phant-abbrev "Build" PhGRK _ _,
1323+
mk-phant-abbrev "Build" PhGRK BuildConst _,
13231324

13241325
std.map Hyps mixin-src_mixin ML,
13251326
if (D = asset-mixin)
@@ -1333,6 +1334,7 @@ declare-mixin-or-factory Sort1 Fields0 GRFS Module TheType D :- std.do! [
13331334
std.map {gr-deps GRK} (_\ r\ r = maximal) Implicits,
13341335
coq.arguments.set-implicit GRK [[maximal|Implicits]] tt,
13351336
acc current (clause _ _ (factory-constructor (indt R) GRK)),
1337+
acc current (clause _ _ (factory-builder-nparams BuildConst 0)),
13361338
coq.env.end-module Exports,
13371339
coq.env.end-module _Module,
13381340

readme.v

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ Notation "- x" := (opp x).
3030
Lemma example (G : AbelianGrp.type) (x : G) : x + (- x) = - 0.
3131
Proof. by rewrite addrC addNr -[LHS](addNr zero) addrC add0r. Qed.
3232

33-
Definition Z_CoMoid := AddComoid_of_Type.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
34-
HB.instance Z Z_CoMoid.
35-
Definition Z_AbGrp := AbelianGrp_of_AddComoid.Build Z Z.opp Z.add_opp_diag_l.
36-
HB.instance Z Z_AbGrp.
33+
HB.instance Definition Z_CoMoid := AddComoid_of_Type.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
34+
HB.instance Definition Z_AbGrp := AbelianGrp_of_AddComoid.Build Z Z.opp Z.add_opp_diag_l.
3735

3836
Lemma example2 (x : Z) : x + (- x) = - 0.
3937
Proof. by rewrite example. Qed.

structures.v

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ pred mixin-src o:term, o:mixinname, o:term.
7979
% Notation Abbrev t1 := (AbbrevSt t1 _ idfun).
8080
pred phant-abbrev o:gref, o:gref, o:abbreviation.
8181

82+
% [factory-builder-nparams Build N] states that when the user writes
83+
% the `F.Build T` abbreviation the term behind it has N arguments before T
84+
pred factory-builder-nparams o:constant, o:int.
85+
8286
% [sub-class C1 C2] C1 is a sub-class of C2.
8387
pred sub-class o:class, o:class.
8488

@@ -251,6 +255,8 @@ Elpi Export HB.structure.
251255
252256
Definition fN : FactoryN T := FactoryN.Build T …
253257
HB.instance T f1 … fN.
258+
259+
HB.instance Definition N := Factory.Build T …
254260
>>
255261
256262
*)
@@ -259,9 +265,18 @@ Elpi Command HB.instance.
259265
Elpi Accumulate File "hb.elpi".
260266
Elpi Accumulate Db hb.db.
261267
Elpi Accumulate lp:{{
268+
main [const-decl Name (some Body) TyWP] :- !, std.do! [
269+
coq.arity->term TyWP Ty,
270+
std.assert-ok! (coq.typecheck Body Ty) "Definition illtyped",
271+
std.assert! (coq.safe-dest-app Body (global (const Builder)) Args) "Not an application of a builder, use a section if you have parameters",
272+
std.assert! (factory-builder-nparams Builder NParams) "Not a factory builder synthesized by HB",
273+
coq.env.add-const Name Body Ty ff ff C,
274+
std.appendR {coq.mk-n-holes NParams} [T|_] Args,
275+
with-attributes (main-declare-canonical-instances T [global (const C)]),
276+
].
262277
main [S|FIS] :- std.map [S|FIS] argument->term [T|FIL], !,
263278
with-attributes (main-declare-canonical-instances T FIL).
264-
main _ :- coq.error "Usage: HB.instance <CarrierTerm> <FactoryInstanceTerm>*".
279+
main _ :- coq.error "Usage: HB.instance <CarrierTerm> <FactoryInstanceTerm>*\nUsage: HB.instance Definition <Name> := <Builder> T ...".
265280

266281
}}.
267282
Elpi Typecheck.

0 commit comments

Comments
 (0)