Skip to content

Commit 2345551

Browse files
authored
Merge pull request #175 from math-comp/improve-doc
some work on the doc
2 parents 7516a95 + cf86a62 commit 2345551

File tree

3 files changed

+88
-72
lines changed

3 files changed

+88
-72
lines changed

HB/structure.elpi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ declare Module B :- std.do! [
9999
phant.add-abbreviation "on_" PhClass _ ClassOfAbbrev,
100100
(pi c\ coq.notation.abbreviation ClassOfAbbrev [c] (ClassOfAbbrev_ c)),
101101

102-
if-verbose (coq.say "HB: declaring Build abbreviation"),
102+
if-verbose (coq.say "HB: declaring `copy` abbreviation"),
103103

104104
coq.mk-app (global ClassName) {params->holes NilwP} AppClassHoles,
105-
@global! => log.coq.notation.add-abbreviation "Build" 2
105+
@global! => log.coq.notation.add-abbreviation "copy" 2
106106
{{fun T C => (lp:(ClassOfAbbrev_ C) : (lp:AppClassHoles T)) }} tt _,
107107

108108
if-verbose (coq.say "HB: declaring on abbreviation"),

structures.v

Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Global Open Scope HB_scope.
4343
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
4444
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
4545

46-
(** This data represents the hierarchy and some othe piece of state to
46+
(** This data represents the hierarchy and some other piece of state to
4747
implement the commands above *)
4848

4949
Elpi Db hb.db lp:{{
@@ -119,7 +119,7 @@ pred factory-nparams o:factoryname, o:int.
119119
pred is-structure o:gref.
120120

121121
% [factory-builder-nparams Build N] states that when the user writes
122-
% the `F.Build T` abbreviation the term behind it has N arguments before T
122+
% the [F.Build T] abbreviation the term behind it has N arguments before T
123123
pred factory-builder-nparams o:constant, o:int.
124124

125125
% [sub-class C1 C2] C1 is a sub-class of C2, see also sub-class? which computes
@@ -215,9 +215,9 @@ Elpi Export HB.status.
215215
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
216216

217217
(** This command prints the hierarchy to a dot file. You can use
218-
<<
219-
tred file.dot | xdot -
220-
>>
218+
[[
219+
tred file.dot | xdot -
220+
]]
221221
to visualize file.dot
222222
*)
223223

@@ -245,14 +245,14 @@ Elpi Export HB.graph.
245245
Syntax to create a mixin [MixinName]
246246
with requirements [Factory1] .. [FactoryN]:
247247
248-
<<
249-
HB.mixin Record MixinName T of Factory1 T & … & FactoryN T := {
250-
op : T -> …
251-
252-
property : forall x : T, op …
253-
254-
}
255-
>>
248+
[[
249+
HB.mixin Record MixinName T of Factory1 T & … & FactoryN T := {
250+
op : T -> …
251+
252+
property : forall x : T, op …
253+
254+
}
255+
]]
256256
257257
Synthesizes:
258258
- [MixinName T] abbreviation for the type of the (degenerate) factory
@@ -296,10 +296,12 @@ Elpi Export HB.mixin.
296296
Syntax to declare a structure combing the axioms from [Factory1] … [FactoryN].
297297
The second syntax has a trailing [&] to pull in factory requirements silently.
298298
299-
<<
300-
HB.structure Definition StructureName params := { A of Factory1 … A & … & FactoryN … A }.
301-
HB.structure Definition StructureName params := { A of Factory1 … A & … & FactoryN … A & }.
302-
>>
299+
[[
300+
HB.structure Definition StructureName params :=
301+
{ A of Factory1 … A & … & FactoryN … A }.
302+
HB.structure Definition StructureName params :=
303+
{ A of Factory1 … A & … & FactoryN … A & }.
304+
]]
303305
304306
Synthesizes:
305307
- [StructureName A] the type of the class that regroups all the factories
@@ -308,26 +310,29 @@ Elpi Export HB.mixin.
308310
- [StructureName.sort params] the first projection of the previous structure,
309311
- [StructureName.clone params T cT] a legacy repackaging function that eta expands
310312
the canonical [StructureName.type] of [T], using [cT] if provided.
311-
- [StructureName.class sT : StructureName sT] outputs the class of [sT : StructureName.type params],
312-
- [StructureName.on T : StructureName sT] outputs the class of the canonical [StructureName.type] on [T].
313-
- [StructureName.Build T cT : StructureName T] outputs the class of the canonical,
314-
and [StructureName.type] of [cT], and give it the type [Structure]. So that it is
313+
- [StructureName.class sT : StructureName sT] projects out the class of [sT : StructureName.type params],
314+
- [StructureName.copy T T' : StructureName T] returns the class of the canonical
315+
[StructureName.type] of [T], and gives it the type [Structure T]. It is thus
315316
ready to use in combination with HB.instance, as in
316-
<<
317-
HB.instance Definition _ := StructureName.Build T cT.
318-
>>
317+
[[
318+
(* Cloning a structure from another one, given by the user *)
319+
HB.instance Definition _ := StructureName.copy T cT.
320+
]]
321+
- [StructureName.on T : StructureName T] infers the class of the canonical
322+
[StructureName.type] of [T]. This is a shortcut for [StructureName.Copy T T],
323+
and it will succeeds if a reduction of [T] is canonically a [StructureName.type].
319324
320325
Disclaimer: any function other that the ones described above, including pattern matching
321-
(using Gallina `match`, `let` or tactics (`case`, `elim`, etc)) is an internal and must
322-
not be relied upon. Also hand-crafted `Canonical` declarations of such structures will
326+
(using Gallina [match], [let] or tactics ([case], [elim], etc)) is an internal and must
327+
not be relied upon. Also hand-crafted [Canonical] declarations of such structures will
323328
break the hierarchy. Use [HB.instance] instead.
324329
325330
Supported attributes:
326331
- [#[mathcomp]] attempts to generate a backward compatibility layer with mathcomp:
327332
trying to infer the right [StructureName.pack],
328333
- [#[infer(variable)]], where [variable : pT] belongs to [params] and is a structure
329-
(e.g. from the hierarchy) with a coercion/canonical projection `pT >-> Sortclass`.
330-
It modifies the notation `StructureName.type` so as to accept [variable : Type] instead,
334+
(e.g. from the hierarchy) with a coercion/canonical projection [pT >-> Sortclass].
335+
It modifies the notation [StructureName.type] so as to accept [variable : Type] instead,
331336
and will try to infer it's [pT] by unification (using canonical structure inference),
332337
This is essential in [Lmodule.type R] where [R] should have type [Ring.type]
333338
but any [Type] which is canonically a [Ring.type] is accepted thanks to [#[infer(R)]].
@@ -336,9 +341,8 @@ Elpi Export HB.mixin.
336341
- [#[arg_sort]] defines an alias [StructureName.arg_sort] for [StructureName.sort],
337342
and declares it as the main coercion. [StructureName.sort] is still declared as a coercion
338343
but the only reason is to make sure Coq does not print it.
339-
Cf https://github.com/math-comp/math-comp/blob/17dd3091e7f809c1385b0c0be43d1f8de4fa6be0/mathcomp/fingroup/fingroup.v#L225-L243.
340-
- [#[verbose]]
341-
344+
Cf #<a href="https://github.com/math-comp/math-comp/blob/17dd3091e7f809c1385b0c0be43d1f8de4fa6be0/mathcomp/fingroup/fingroup.v##L225-L243">#[fingroup.v]#</a>#.
345+
- [#[verbose]] for a verbose output.
342346
*)
343347

344348
Elpi Command HB.structure.
@@ -358,6 +362,7 @@ Elpi Accumulate lp:{{
358362

359363
main [const-decl N (some B) _] :- !, with-attributes (with-logging (structure.declare N B)).
360364
main _ :- coq.error "Usage: HB.structure Definition <ModuleName> := { A of <Factory1> A & … & <FactoryN> A }".
365+
361366
}}.
362367
Elpi Typecheck.
363368
Elpi Export HB.structure.
@@ -367,19 +372,18 @@ Elpi Export HB.structure.
367372
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
368373

369374
(** [HB.instance] associates to a type all the structures that can be
370-
obtaind from the provided factory inhabitant.
375+
obtained from the provided factory inhabitant.
371376
372377
Syntax for declaring a canonical instance:
373378
374-
<<
375-
HB.instance Definition N Params := Factory.Build Params T …
376-
>>
379+
[[
380+
HB.instance Definition N Params := Factory.Build Params T …
381+
]]
377382
378-
Attributes:
379-
- [#[export]] to flag the instance so that it is redeclared by #[HB.reexport]
383+
Supported attributes:
384+
- [#[export]] to flag the instance so that it is redeclared by [#[HB.reexport]]
380385
- [#[local]] to indicate that the instance should not survive the section.
381-
- [#[verbose]]
382-
386+
- [#[verbose]] for a verbose output.
383387
*)
384388

385389
Elpi Command HB.instance.
@@ -441,13 +445,13 @@ Elpi Export HB.factory.
441445
442446
Syntax to declare builders for factory [Factory]:
443447
444-
<<
445-
HB.builders Context A (f : Factory A).
446-
447-
HB.instance A someFactoryInstance.
448-
449-
HB.end.
450-
>>
448+
[[
449+
HB.builders Context A (f : Factory A).
450+
451+
HB.instance A someFactoryInstance.
452+
453+
HB.end.
454+
]]
451455
452456
[HB.builders] starts a section (inside a module of unspecified name) where:
453457
- [A] is a type variable
@@ -464,9 +468,9 @@ Elpi Export HB.factory.
464468
- for each structure inhabited via [HB.instance] it defined all
465469
builders to known mixins
466470
467-
Supported attributes: [#[verbose]]
468-
469-
*)
471+
Supported attributes:
472+
- [#[verbose]] for a verbose output.
473+
*)
470474

471475
Elpi Command HB.builders.
472476
Elpi Accumulate File "HB/common/stdpp.elpi".
@@ -514,15 +518,20 @@ Elpi Export HB.end.
514518
to be exported later on, when [HB.reexport] is called.
515519
Note that the list of modules to be exported is stored in the current module,
516520
hence the recommended way to do is
517-
<<<
518-
Module Algebra.
519-
HB.mixin .... HB.structure ...
520-
Module MoreExports. ... End MoreExports. HB.export MoreExports.
521-
...
522-
Module Export. HB.reexport. End Exports.
523-
End Algebra.
524-
Export Algebra.Exports.
525-
>>> *)
521+
[[
522+
Module Algebra.
523+
HB.mixin .... HB.structure ...
524+
Module MoreExports. ... End MoreExports. HB.export MoreExports.
525+
...
526+
Module Export. HB.reexport. End Exports.
527+
End Algebra.
528+
Export Algebra.Exports.
529+
]]
530+
531+
Supported attributes:
532+
- [#[verbose]] for a verbose output.
533+
534+
*)
526535

527536
Elpi Command HB.export.
528537
Elpi Accumulate File "HB/common/stdpp.elpi".
@@ -564,32 +573,39 @@ Elpi Export HB.reexport.
564573
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
565574
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
566575
567-
(** This command populates the current section with canonical instances.
576+
(*
577+
Inactive command: [HB.context]
578+
This command populates the current section with canonical instances.
568579
569580
Input:
570581
- the name of a section variable of type Type
571582
- zero or more factories
572583
573584
Effect:
574-
575-
Variable m0 : m0.
576-
Definition s0 := S0.Pack T (S0.Build T m0).
577-
Canonical s0.
578-
..
579-
Variable mn : mn dn.
580-
Definition sm : SM.Pack T (SM.Build T m0 .. mn).
581-
Canonical sm.
585+
[[
586+
Variable m0 : m0.
587+
Definition s0 := S0.Pack T (S0.Build T m0).
588+
Canonical s0.
589+
..
590+
Variable mn : mn dn.
591+
Definition sm : SM.Pack T (SM.Build T m0 .. mn).
592+
Canonical sm.
593+
]]
582594
583595
where:
584596
- factories produce mixins m0 .. mn
585597
- mixin mn depends on mixins dn
586598
- all structures that can be generated out of the mixins are declared
587599
as canonical
588600
589-
% TODO perform a check that the declarations are closed under dependencies
601+
602+
Supported attributes:
603+
- [#[verbose]] for a verbose output.
590604
591605
*)
592606
607+
(* TODO perform a check that the declarations are closed under dependencies *)
608+
593609
Elpi Command HB.context.
594610
Elpi Accumulate File "HB/common/stdpp.elpi".
595611
Elpi Accumulate File "HB/common/utils.elpi".

tests/class_for.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Definition unit' := unit.
99
HB.instance Definition _ := isInhab.Build unit' tt.
1010
Check Inhab.of unit'.
1111
Fail Check Inhab.of unit.
12-
HB.instance Definition _ := Inhab.Build unit unit'.
12+
HB.instance Definition _ := Inhab.copy unit unit'.
1313
Check Inhab.of unit.
1414

1515
(* with params *)
@@ -21,6 +21,6 @@ Definition bool' := bool.
2121
HB.instance Definition _ := isInhabIf.Build true bool' (fun=> false).
2222
Check InhabIf.of bool'.
2323
Fail Check InhabIf.of bool.
24-
HB.instance Definition _ := InhabIf.Build bool bool'.
24+
HB.instance Definition _ := InhabIf.copy bool bool'.
2525
Check InhabIf.of bool.
2626
Check (y (Phant bool) : bool).

0 commit comments

Comments
 (0)