-
Notifications
You must be signed in to change notification settings - Fork 115
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
How to use auto-derivation with contravariant TC #336
Comments
HI, this might be connected to scala/scala3#13146 |
Well yes and no :) In the linked issue it is said that this is due to the limitation of the type inference. Providing more information to the compiler using alternative syntax solves this problem. In my linked example I have already done it for the sealed trait Tree[+T] derives Eq
object Tree:
given [T: [X] =>> Show[String, X]] : Show[String, Tree[T]] = Show.derived was replaced with sealed trait Tree[+T]
object Tree:
given [T: [X] =>> Show[String, X]] : Show[String, Tree[T]] = Show.derived
given lEq[T: Eq] : Eq[Leaf[T]] = Eq.derived[Leaf[T]]
given bEq[T: Eq] : Eq[Branch[T]] = Eq.derived[Branch[T]]
given tEq[T : Eq]: Eq[Tree[T]] = Eq.derived[Tree[T]] But the Last but not least it seems like a good idea to incorporate some tests against contravariant type-classes into magnolia's test suite. |
@ghostbuster91 what if you add an explicit type parameter to |
@adamw I mentioned the change in with summoning an implicit instant: This change alone (without going contravariant) works, but combined with contravariant modification it fails to compile. All the changes can be seen in this single commit: ghostbuster91@3e5c919 |
@ghostbuster91 object Entity:
given Eq[Entity] = Eq.derived[Entity]
given Eq[Person] = Eq.derived[Person]
given Eq[Company] = Eq.derived[Company] |
No problem :) But that seems like a semi-auto derivation, doesn't it? |
Yes, it does. But that feels like a dotty bug since the instance is generated correctly. The only problem is with finding already existing instances. |
Came here from diffx. Thanks for looking at this @ghostbuster91 and @KacperFKorban. Do we have a way forward or are we still blocked by scala/scala3#13146? Happy to help out if needed |
Hi @dantb I created a new scala-3 migration branch (softwaremill/diffx#311) as the previous one got a little bit stale and messy. However, the old one was very useful as it showed some problematic areas. With regards to what is there still needed to be done please refer to the TODO list in the PR. Any help would be greatly appreciated :) When it comes to blockers, auto-derivation seems to be out of the game, but semi-auto generally works. @KacperFKorban Do you think that scala/scala3#13146 covers that problem with auto-derivation or should we create a separate issue? |
I think that this dotty issue is unlikely to be solved in the near future. It seams like a limitation and not a bug. Maybe we will have to hack something on magnolia side. |
Hi,
I am struggling with the migration of diffx to scala3, especially with the derivation mechanism.
I did a quick check and it seems that changing the
Eq
tc from magnolia examples also doesn't work. It fails with the following error:Am I missing something? Has somebody tried already something like that?
Full code to reproduce this error can be found here: https://github.com/ghostbuster91/magnolia/tree/contravariant-derivation-3
Notice that calling derivation explicitly
Eq.derived[Person]
works without any problems.The text was updated successfully, but these errors were encountered: