math-comp / hierarchy-builder

High level commands to declare a hierarchy based on packed classes
MIT License
97 stars 21 forks source link

`#[primitive] HB.mixin` breaks the types of constants lifting mixin projections #386

Open pi8027 opened 1 year ago

pi8027 commented 1 year ago

Example:

From Coq Require Import ssreflect ssrfun.
From HB Require Import structures.

#[primitive]
HB.mixin Record AddMonoid_of_TYPE S := {
  zero : S;
  add : S -> S -> S;
  addrA : associative add;
  add0r : left_id zero add;
  addr0 : right_id zero add;
}.

HB.structure Definition AddMonoid := { A of AddMonoid_of_TYPE A }.

Check addrA.
(*
addrA
     : associative (AddMonoid_of_TYPE.add _ (AddMonoid.class ?s))
where
?s : [ |- AddMonoid.type]
*)

The type of addrA should be associative add.

gares commented 1 year ago

Iirc there is a piece of code cleaning up the type. I guess it is broken if the primitive term constructors shows up

pi8027 commented 1 year ago

@gares Can you point out the part of the code declaring these constants and synthesizing their types? I have a rough idea of how to fix the issue.

gares commented 1 year ago

clean-op-ty in structure.elpi is what I suspect messes up things.

gares commented 1 year ago

https://github.com/math-comp/hierarchy-builder/blob/7d4f0958c37d6c006569892c742d7c7bb70279e1/HB/structure.elpi#L201-L237

pi8027 commented 1 year ago

Thanks. I believe that constructing the types of these constants from the declaration of the record type is much easier than doing so from the types of the projections. While the latter requires some replacements using copy (as we can see in clean-op-ty), the former should be just a matter of substitution.

pi8027 commented 1 year ago

I will take a closer look when I have some time.