Closed cpitclaudel closed 3 years ago
I think it's likely that I'm doing something wrong though, because a simpler example fails too:
From mathcomp Require Import ssreflect ssrnat eqtype.
From deriving Require Import deriving.
Inductive reg_t := r0.
Definition reg_t_eqMixin := [derive eqMixin for reg_t].
Canonical reg_t_eqType := EqType reg_t reg_t_eqMixin.
(Btw, what's the foo_indMixin
that the readme refers to? Should it be foo_indDef
?)
(Btw, what's the
foo_indMixin
that the readme refers to? Should it befoo_indDef
?)
It was a typo; thanks for catching it!
The error you saw arises because that notation triggers a canonical structure inference for an instance of indType
over reg_t
, which fails because no such instance has been declared. Here is the fix:
From mathcomp Require Import ssreflect ssrnat eqtype.
From deriving Require Import deriving.
Inductive reg_t := r0.
Definition reg_t_indDef := [indDef for reg_t_rect].
Canonical reg_t_indType := IndType reg_t reg_t_indDef.
Definition reg_t_eqMixin := [derive eqMixin for reg_t].
Canonical reg_t_eqType := EqType reg_t reg_t_eqMixin.
For your more complex type, before defining reg_t_eqMixin
, you need to also make sure that every argument of reg_t
is also declared as an instance of the class you are deriving (in this case, eqType
). You don't need to declare instances of indType
for them. Note that deriving does not provide support for types like index
, so you would need to write an eqType
instance for it by hand.
Thanks! I will look into all this :)
Hi there,
In Kôika we have been deriving instances of custom EqDec and FiniteType typeclasses using Ltac, and the code is neither fast nor pretty, so I got intrigued by your Discourse announcement. Do you have tips on dealing with the following error? (I used the eqtype example from the readme on one of our types.
The type that I'm looking at:
The first few constructors have parameters
….reg_t
which are all relatively simple; for example:Although the
Rf.reg_t
one is more complicated:(
index
is our fixpoint-based equivalent ofFin.t
)Let me know if you would like a pointer to the code.