You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduced the issue to a self-contained, reproducible test case.
Description
When defining an OfNat instance for a small sum type, instance resolution only works when the Nat constructors are written out fully explicitly, rather than as Nat literals themselves.
Steps to Reproduce
Write the following:
inductive Bit where
| zero
| one
instance : OfNat Bit 0 where
ofNat := Bit.zero
instance : OfNat Bit 1 where
ofNat := Bit.one
example : Bit := 0
Expected behavior:
I expect the example to be defined to mean Bit.zero
inductive Bit where
| zero
| one
instance : OfNat Bit Nat.zero where
ofNat := Bit.zero
instance : OfNat Bit (Nat.succ Nat.zero) where
ofNat := Bit.one
example : Bit := 0
However, it quickly gets tiring and error-prone if the datatype has a few more constructors.
The text was updated successfully, but these errors were encountered:
@Kha This issue has been raised so many times. I am considering writing code for converting the numeric literals occurring in OfNat instances to nat_lits.
The docs linked to from #875 took me a long time to figure out, and I think it would have ended up with a fairly long explanation in the book. Much better to just make it easier :-)
Prerequisites
Description
When defining an
OfNat
instance for a small sum type, instance resolution only works when theNat
constructors are written out fully explicitly, rather than asNat
literals themselves.Steps to Reproduce
Write the following:
Expected behavior:
I expect the example to be defined to mean
Bit.zero
Actual behavior:
This error:
Reproduces how often:
100%
Versions
I'm running Fedora 36
Additional Information
I can work around the issue as follows:
However, it quickly gets tiring and error-prone if the datatype has a few more constructors.
The text was updated successfully, but these errors were encountered: