@@ -660,6 +660,7 @@ type mterm list term -> term -> list mixinname -> term -> mterm.
660660% - [id] using [unify-arg]
661661kind phant-arg type.
662662type real-arg name -> phant-arg.
663+ type infer-type name -> phant-arg.
663664type implicit-arg phant-arg.
664665type unify-arg phant-arg.
665666
@@ -934,6 +935,9 @@ mk-phant-abbrev.term K F [] K F.
934935mk-phant-abbrev.term K F [real-arg N|AL] K'' (fun N _ AbbrevFx) :- !,
935936 pi x\ mk-phant-abbrev.term K {mk-app F [x]} AL K' (AbbrevFx x),
936937 K'' is K' + 1.
938+ mk-phant-abbrev.term K F [infer-type N|AL] K'' (fun N _ AbbrevFx) :- !,
939+ pi x\ mk-phant-abbrev.term K {mk-app F [{{ lib:hb.Phant lp:x }}]} AL K' (AbbrevFx x),
940+ K'' is K' + 1.
937941mk-phant-abbrev.term K F [implicit-arg|AL] K' FAbbrev :- !,
938942 mk-phant-abbrev.term K {mk-app F [_]} AL K' FAbbrev.
939943mk-phant-abbrev.term K F [unify-arg|AL] K' FAbbrev :- !,
@@ -1513,7 +1517,8 @@ synthesize-fields.body _Params T ML (record "axioms" {{ Type }} "Class" FS) :-
15131517 synthesize-fields T ML FS.
15141518
15151519pred mk-record+sort-field i:name, i:term, i:(term -> record-decl), o:indt-decl.
1516- mk-record+sort-field _ T F (record "type" {{ Type }} "Pack" (field _ "sort" T F)).
1520+ mk-record+sort-field _ T F (record RecordName {{ Type }} "Pack" (field _ "sort" T F)) :-
1521+ if (get-option "infer" _) (RecordName = "type_") (RecordName = "type").
15171522
15181523pred mk-class-field i:classname, i:list term, i:term, i:list (w-args mixinname), o:record-decl.
15191524mk-class-field ClassName Params T _ (field _ "class" (app [global ClassName|Args]) _\end-record) :-
@@ -1648,6 +1653,24 @@ pack-body ClassName PL T MLwA F :- std.do! [
16481653 under-mixins.then MLwA mk-fun (pack-body.mixins PL T BuildC PackS) F
16491654].
16501655
1656+ pred declare-auto-infer-params-abbrev i:structure, i:list-w-params mixinname.
1657+ declare-auto-infer-params-abbrev GR MLwP :- get-option "infer" Map, !,
1658+ Map => mk-infer (global GR) MLwP PHARGS TSK,
1659+ std.assert-ok! (coq.elaborate-skeleton TSK _ T) "infer illtyped",
1660+ mk-phant-abbrev "type" (phant-term PHARGS T) _ _.
1661+ declare-auto-infer-params-abbrev _ _.
1662+
1663+ pred mk-infer i:term, i:list-w-params mixinname, o:list phant-arg, o:term.
1664+ mk-infer T (w-params.nil _ _ _) [] T.
1665+ mk-infer T (w-params.cons N Ty W) [implicit-arg, infer-type N|A] R1 :- coq.name->id N ID, (get-option ID "Type" ; get-option ID ""), !,
1666+ R1 = (fun N Ty n\ fun `ph` {{ lib:@hb.phant lp:n }} _\ R n),
1667+ @pi-decl N Ty n\
1668+ mk-infer {mk-app T [n]} (W n) A (R n).
1669+ mk-infer T (w-params.cons N Ty W) [real-arg N|A] (fun N Ty R) :- coq.name->id N ID, not (get-option ID _), !,
1670+ @pi-decl N Ty x\ mk-infer {mk-app T [x]} (W x) A (R x).
1671+ mk-infer _ (w-params.cons N _ _) _ _ :- coq.name->id N ID, get-option ID Infer,
1672+ coq.error "Automatic inference of paramter" N "from" Infer "not supported".
1673+
16511674% HB.structure Definition S P1 P2 := { T of F1 P1 T & F2 P1 (P2*P2) T }
16521675% cons p1\ cons p2\ nil t\ [triple f1 [p1] t,triple f2 [p1, {{p1 * p2}}] t]
16531676pred main-declare-structure i:string, i:list-w-params gref, i:bool.
@@ -1682,6 +1705,8 @@ main-declare-structure Module GRFSwP ClosureCheck :- std.do! [
16821705 ClassRequires = factory-requires (ClassName) NilwP,
16831706 ClassAlias = (factory-alias->gref ClassName ClassName),
16841707 CurrentClass = (class ClassName Structure MLwP),
1708+
1709+ declare-auto-infer-params-abbrev Structure MLwP,
16851710
16861711 if-verbose (coq.say "HB: declaring clone abbreviation"),
16871712
@@ -2227,4 +2252,4 @@ declare-mixin-or-factory Sort1 Fields GRFSwP Module TheType D TheParams :- std.d
22272252 export Exports,
22282253
22292254 declare-factory-abbrev Module FactAbbrev,
2230- ].
2255+ ].
0 commit comments