@@ -13,8 +13,8 @@ declare Module BSkel Sort :- std.do! [
1313 re-enable-id-phant BNoId B,
1414 private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck,
1515
16- % do some work to go back to
17- GRFSwP_or_ThingtoBeWrapped = GRFSwP,
16+ % do some work to go back to factories on a single subject
17+ private.lift-to-the-subject GRFSwP_or_ThingtoBeWrapped GRFSwP,
1818
1919 factories-provide GRFSwP PMLwP,
2020
@@ -713,17 +713,35 @@ if-coverage-not-good-error.one _ _. % new class is the first covering M
713713% use that structure to synthesize the type of the wrapper, eg
714714% hom belongs to Quiver, hence hom_isMon takes a "T of Quiver T"
715715
716- pred product->triples i:term, o:list (w-args factoryname), o:bool.
717- product->triples {{ lib:hb.prod lp:A lp:B }} L ClosureCheck :- !,
718- product->triples B GRB ClosureCheck,
719- product->triples A GRA _,
716+ % checks if the term is forall A B C, Factory ... (Op A B C) ...
717+ pred factory-on-some-structure-op? i:term, i:list term, o:gref, o:constant.
718+ factory-on-some-structure-op? (prod N Ty Bo) VS F OP :-
719+ @pi-decl N Ty x\
720+ factory-on-some-structure-op? (Bo x) [x|VS] F OP.
721+ factory-on-some-structure-op? T VS F OP :-
722+ factory? T (triple F _ Subject),
723+ coq.safe-dest-app Subject (global (const OP)) Args,
724+ exported-op _ _ OP,
725+ std.appendR _ {std.rev VS} Args.
726+
727+ kind factory-on-subject type.
728+ type factory-on-the-type w-args factoryname -> factory-on-subject.
729+ type factory-on-structure-op term -> factoryname -> constant -> factory-on-subject.
730+
731+ pred product->triples i:term, i:term, o:list factory-on-subject, o:bool.
732+ product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !,
733+ product->triples B T GRB ClosureCheck,
734+ product->triples A T GRA _,
720735 std.append GRA GRB L.
721- product->triples {{ True }} [] tt :- !.
722- product->triples {{ False }} [] ff :- !.
723- product->triples A [GR] tt :- std.assert! (factory? A GR) "A structure can only mention known factories".
724- % product->triples A [GR] tt :- factory-on-some-structure-op? A GR.
725-
726- pred sigT->list-w-params i:term, o:list-w-params factoryname, o:bool.
736+ product->triples {{ True }} _ [] tt :- !.
737+ product->triples {{ False }} _ [] ff :- !.
738+ product->triples A T [factory-on-the-type F] tt :- factory? A F, F = triple _ _ T, !.
739+ product->triples A _ [factory-on-structure-op A F OP] tt :- factory-on-some-structure-op? A [] F OP, !.
740+ product->triples A T _ _ :-
741+ coq.error "HB: expecting a factory on" {coq.term->string T}
742+ "or a factory on a structure operation. Got:" {coq.term->string A}.
743+
744+ pred sigT->list-w-params i:term, o:w-params (list factory-on-subject), o:bool.
727745sigT->list-w-params (fun N T B) L C :-
728746 coq.name->id N ID, % TODO: we should read the ID from the definition type which is an arity containing ids
729747 L = w-params.cons ID T Rest,
@@ -733,7 +751,28 @@ sigT->list-w-params {{ lib:@hb.sigT _ lp:{{ fun N Ty B }} }} L C :-
733751 coq.name->id N ID, % TODO: we should read the ID from the definition type which is an arity containing ids
734752 L = w-params.nil ID Ty Rest,
735753 @pi-decl N Ty t\
736- product->triples (B t) (Rest t) C.
754+ product->triples (B t) t (Rest t) C.
755+
756+ pred lift-to-the-subject i:w-params (list factory-on-subject), o:list-w-params factoryname.
757+ lift-to-the-subject (w-params.cons ID T Rest) (w-params.cons ID T Rest1) :-
758+ @pi-parameter ID T x\
759+ lift-to-the-subject (Rest x) (Rest1 x).
760+ lift-to-the-subject (w-params.nil ID T Rest) (w-params.nil ID T Rest1) :-
761+ @pi-parameter ID T x\
762+ lift-to-the-subject.aux (Rest x) x (Rest1 x).
763+ lift-to-the-subject.aux [] _ [].
764+ lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :-
765+ lift-to-the-subject.aux Rest T Rest1.
766+ lift-to-the-subject.aux [factory-on-structure-op Expr F OP|Rest] T [WF|Rest1] :-
767+ wrapper-mixin Wrapper (const OP) F, !,
768+ factory-nparams Wrapper NParams,
769+ coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W,
770+ factory? W WF,
771+ coq.say Expr "->" WF,
772+ lift-to-the-subject.aux Rest T Rest1.
773+ lift-to-the-subject.aux [factory-on-structure-op Expr _ _|_] _ _ :-
774+ coq.error "NYI: automatic wrapping for" {coq.term->string Expr}.
775+
737776
738777pred mk-hb-eta.on i:structure, i:term, i:abbreviation,
739778 i:list term, i:name, i:term, i:A, o:term.
0 commit comments