-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add bounds to CoproductInstances methods #41
Conversation
This restricts the implementation of sums to subtypes, but this implementation is already restricted by `Mirror.Sum` which is used in `ErasedCoproductInstances`. This allows us to implement coproduct folds that return the upper bound as a result, e.g. that would replace `traverse`.
@@ -102,7 +102,7 @@ class InstancesTests { | |||
|
|||
val expected = "f 326" | |||
val actual = otherInst.fold[String](f) { | |||
[t] => (f: AnotherTypeClass[t], t: t) => "f " + f.method(t) | |||
[t <: Few[Int]] => (f: AnotherTypeClass[t], t: t) => "f " + f.method(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why this was necessary - the poly function without a bound should be a subtype
This seems to be in direct conflict with an attempt to fix #21. Suppose we, or some other library, or an application, provided |
Unions are still super types. Where it could break down is e.g. with a nested |
Maybe the alternative is to provide an |
I'm not keen on that, because we want the erased operation to be just a cast.
This is right of course, so I don't actually have any objections here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This restricts the implementation of sums to subtypes,
but this implementation is already restricted by
Mirror.Sum
which is used in
ErasedCoproductInstances
.This allows us to implement coproduct folds that return the
upper bound as a result, e.g. that would replace
traverse
.