-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defer could use some additional instances #4413
Comments
This is a really nice observation! |
If nobody can remember why not, I think this is a splendid idea. |
@rossabaker I think we have actually just not implemented all the type-classes on type-classes that we have. We should add them. Especially the first order type classes |
Defer
is really handy when writing typeclass instances for generic recursive ADTs, and unfortunately it's currently missing most of the instances that tend to be useful for this shape of data type.I'd like to add
Defer
instances for the following typeclasses:Eq
Order
Hash
Show
I'd also like to add
Defer
instances for these related typeclasses, mostly for completeness:Equiv
Ordering
PartialOrder
PartialOrdering
As an example of how fiddly this can be, a simplified
Test[A]
has this shape:The sort of instance which would work for this if
Test
weren't generic looks like this:scastie
Unfortunately, because it doesn't provide a stable implicit, it generates a new instance every time it recurses.
Implementing an anonymous subclass can avoid this, but only if an implicit self-reference is added:
scastie
In comparison,
Defer
results in an idiomatic implementation that neatly avoids the easy errors of the other versions:scastie
The text was updated successfully, but these errors were encountered: