Skip to content

Commit c53a6f2

Browse files
authored
Merge pull request #101 from math-comp/class-to-mixin-coercions
Adding coercions from classes to mixins
2 parents d94d00e + e4c9982 commit c53a6f2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

default.nix

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{withEmacs ? false,
2-
nixpkgs ? (fetchTarball {
3-
url = "https://github.com/NixOS/nixpkgs-channels/archive/0a9d9946ed3e1ec526848db2f77f2dc978b46bb5.tar.gz";
4-
sha256 = "1gdqnb5g5h47gqx95lyzlqnmhzkcnh27gia778cr79cmgvwasb69";
5-
}),
2+
nixpkgs ? (fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/e97fdce4e1b945c9ec30d4d90a451f1577f5cf4a.tar.gz),
63
coq-version ? "8.11",
74
print-env ? false
85
}:
96
with import nixpkgs {
107
overlays = [ (super: self: {
118
coqPackages = { "8.11" = super.coqPackages_8_11; }."${coq-version}".overrideScope' (self: super: {
12-
## Coq package override example:
13-
# coq-elpi = super.coq-elpi.overrideAttrs (old: {
14-
# name = "coq8.11-elpi-v1.4.0";
15-
# src = fetchTarball https://github.com/LPCIC/coq-elpi/archive/v1.4.0.tar.gz;
9+
# Coq package override example:
10+
coq-elpi = super.coq-elpi.overrideAttrs (old: {
11+
name = "coq8.11-elpi-1.5.0";
12+
src = fetchTarball https://github.com/LPCIC/coq-elpi/archive/v1.5.0.tar.gz;
13+
});
1614
});
1715
coq = self.coqPackages.coq;
1816
})];

hb.elpi

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,16 @@ if-class-already-exists-error N [class _ S ML1wP|CS] ML2 :-
14571457
(coq.error "Structure" {coq.term->string S} "contains the same mixins of" N)
14581458
(if-class-already-exists-error N CS ML2).
14591459

1460+
pred export-mixin-coercion i:classname, i:option constant.
1461+
export-mixin-coercion _ none.
1462+
export-mixin-coercion ClassName (some C) :-
1463+
coq.env.typeof (const C) CTy,
1464+
safe-dest-app {safe-head CTy} Mixin _,
1465+
coq.term->gref Mixin MixinGR,
1466+
if-verbose (coq.say "export-mixin-coercion: from" ClassName "to" MixinGR),
1467+
@global! =>
1468+
coq.coercion.declare (coercion (const C) _ ClassName (grefclass MixinGR)).
1469+
14601470
% HB.structure Definition S P1 P2 := { T of F1 P1 T & F2 P1 (P2*P2) T }
14611471
% cons p1\ cons p2\ nil t\ [triple f1 [p1] t,triple f2 [p1, {{p1 * p2}}] t]
14621472
pred main-declare-structure i:string, i:list-w-params gref, i:bool.
@@ -1508,6 +1518,14 @@ main-declare-structure Module GRFSwP ClosureCheck :- std.do! [
15081518
declare-unification-hints SortProjection ClassProjection CurrentClass NewJoins,
15091519
% Register in Elpi's DB the new structure
15101520
% NOT TODO: All these acc are correctly locaed in an Export Module
1521+
1522+
if (ClassName = indt ClassInd) (std.do![
1523+
if-verbose (coq.say "HB: exporting coercions from class to mixins"),
1524+
std.forall {coq.CS.canonical-projections ClassInd}
1525+
(export-mixin-coercion ClassName)
1526+
])
1527+
(coq.say "declare-structure:" ClassName "should be an inductive", fail),
1528+
15111529
if-verbose (coq.say "HB: accumulating various props"),
15121530
std.forall MLToExport (m\ acc current (clause _ _ (mixin-first-class m ClassName))),
15131531
std.forall EX (ex\ acc current (clause _ _ ex)),
@@ -1698,7 +1716,7 @@ is-last-named-asset-param (asset-parameter _ _ _\ asset-alias _ _) :- !.
16981716

16991717
% main-declare-asset Asset AssetKind
17001718
pred main-declare-asset i:asset-decl, i:asset.
1701-
main-declare-asset Asset AssetKind :-
1719+
main-declare-asset Asset AssetKind :-
17021720
% since we turn locally bound variables into global constrants the holes
17031721
% in the input term can go outside the pattern fragment, but we don't care
17041722
@holes! => std.do! [

0 commit comments

Comments
 (0)