Zulip Chat Archive
Stream: general
Topic: Mutual Recursive Typeclass Methods Between Two Instances?
Segev Elazar Mittelman (Sep 23 2025 at 19:51):
Is there any way to create two typeclass instances, each of which containing a function, with those functions being mutually recursive, without defining the functions in a mutual block outside the instances first?
Kenny Lau (Sep 23 2025 at 19:52):
probably not
Aaron Liu (Sep 23 2025 at 20:49):
if the typeclass is an abbrev for a function then maybe
Aaron Liu (Sep 23 2025 at 20:49):
if the typeclass is a structure then no
Segev Elazar Mittelman (Sep 23 2025 at 20:51):
What would a typeclass that is an abbrev for a function look like? Just a typeclass with a single function method and nothing else or do I have to use the abbrev keyword somewhere?
Kenny Lau (Sep 23 2025 at 20:53):
I don't think that's legal, I think the following is what Aaron intended, but Lean complains:
@[class] abbrev Foo := Nat → Nat
Aaron Liu (Sep 23 2025 at 20:53):
Aaron Liu (Sep 23 2025 at 20:53):
is a typeclass
Aaron Liu (Sep 23 2025 at 20:53):
but also an abbrev for a function
Segev Elazar Mittelman (Sep 23 2025 at 20:54):
Ah, and it supports mutual types right?
Aaron Liu (Sep 23 2025 at 20:54):
no idea what that means
Aaron Liu (Sep 23 2025 at 20:54):
like mutual inductive types or
Kenny Lau (Sep 23 2025 at 20:55):
mutual recursion probably
Aaron Liu (Sep 23 2025 at 20:55):
oh
Segev Elazar Mittelman (Sep 23 2025 at 20:55):
Sorry brain misfire, I'm thinking in the context of deriving DecidableEq, how do they derive it for mutually inductive types
Aaron Liu (Sep 23 2025 at 20:55):
oh they don't
Aaron Liu (Sep 23 2025 at 20:55):
I don't think they do
Aaron Liu (Sep 23 2025 at 20:55):
not yet at least
Segev Elazar Mittelman (Sep 23 2025 at 20:56):
But it should be possible since its an abbrev?
Kenny Lau (Sep 23 2025 at 20:56):
there's basically not much support :tm: for anything "mutual" that you want to make
Segev Elazar Mittelman (Sep 23 2025 at 21:00):
Ah that's trouble. I'm trying to derive some mutually dependent typeclasses via metaprogramming, one example being a typechecker mutually defined with a type inferrer.
Kenny Lau (Sep 23 2025 at 21:01):
by metaprogramming do you mean "I won't prove anything with my definitions"?
Segev Elazar Mittelman (Sep 23 2025 at 21:03):
That's not what I mean by it but I probably won't prove anything with these definitions. They're for use in a QuickChick style PBT library.
Segev Elazar Mittelman (Sep 23 2025 at 21:05):
The metaprogramming is for syntactically analyzing an inductive relation then extracting various functions from it.
Segev Elazar Mittelman (Sep 23 2025 at 21:11):
Btw, deriving DecidableEq does support mutual inductives, it just defines a mutual block of the decEq functions then later creates instances.
Last updated: Dec 20 2025 at 21:32 UTC