Can't define typeclasses for union and intersection types #12270
japgolly
started this conversation in
General Discussion
Replies: 2 comments 1 reply
-
That's currently beyond the scope of what's possible. These things are ambiguous according to the rules of implicit search in the language spec. Extending the language spec to allow looks non-trivial. It will probably require major research. Moving to discussions. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I thought so too initially, but commutativity means that we can't expect things to be broken down like this. You can use opaque type aliases though |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Compiler version
3.0.0-RC3
Minimized code
Output
Expectation
It should compile. We need a way to generically define typeclasses for unions and intersection types.
I think what's happening is that, because union and intersection types are commutative, the implicit search correctly identifies that
A | B
can be reversed toB | A
in order to satisfy its search. In this case at least, it doesn't matter which is chosen - they're identical so implicit search should just chooseA | B
.Beta Was this translation helpful? Give feedback.
All reactions