I’m encoding a HOAS in Coq, but my coercions are not working well.
Here is a MWE:
From Coq Require Import ZArith String.
Variant tag := A | B.
Variant const := Unit | Int : Z -> const.
Inductive expr : tag -> Type :=
| Const {tag} (c : const) : expr tag
| Var {tag} (x : string) : expr tag
| AB (e : expr A) : expr B.
Open Scope Z_scope.
Open Scope string_scope.
Declare Custom Entry syntax.
Notation "'<{' e '}>'" := e (e custom syntax at level 99).
Notation "x" := x (in custom syntax at level 0, x constr at level 0).
Notation "'()'" := (Const Unit) (in custom syntax at level 0).
Coercion Int : Z >-> const.
Coercion Const : const >-> expr.
Coercion Var : string >-> expr.
Notation "'!' e" := (AB e) (right associativity, in custom syntax at level 1).
Set Printing Coercions.
Check <{ !"x" }>.
which works quite well:
<{ ! (Var "x") }>
: expr B
But my Const
and Var
coercions give warnings, e.g.,
Var does not respect the uniform inheritance condition.
[uniform-inheritance,coercions,default]
Var is now a coercion
I believe it is due to the tag
input, but I’m not sure how to resolve this warning.
Thanks!