Zulip Chat Archive
Stream: Is there code for X?
Topic: Is there a way to remove an instance?
Freek Wiedijk (May 03 2024 at 17:40):
I would like n - m
not to work for natural numbers (so when I write that, then n
and m
would be coerced to integers first, and the subtraction would be on the integers). I guess for that I'd need to remove an instance of a type class? So is that possible, and if so, how do I do that?
Matthew Ballard (May 03 2024 at 17:52):
instance (priority := high) foo : HSub Nat Nat Int where
hSub n m := n - m
seems to work for me without removing docs#instSubNat
Adam Topaz (May 03 2024 at 17:54):
attribute [-instance] instSubNat
#eval (1 : Nat) - 3
/-
failed to synthesize instance
HSub Nat Nat ?m.42
-/
Adam Topaz (May 03 2024 at 17:55):
But this would make things quite inconvenient.
Matthew Ballard (May 03 2024 at 17:55):
Adam actually answers the question lol.
Note this removal is local to the file whereas the high priority hetero sub persists
Kyle Miller (May 03 2024 at 18:40):
That heterogenous instance might interact poorly with expression elaboration (i.e., binop%
), so if you use it just be on the lookout for weird results (and please let me know).
Last updated: May 02 2025 at 03:31 UTC