Skip to content
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

Merged
merged 1 commit into from
Oct 11, 2021
Merged

Conversation

joroKr21
Copy link
Member

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.

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)
Copy link
Member Author

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

@milessabin
Copy link
Member

This seems to be in direct conflict with an attempt to fix #21. Suppose we, or some other library, or an application, provided Mirror instances for union types?

@joroKr21
Copy link
Member Author

Unions are still super types. Where it could break down is e.g. with a nested Either encoding - but in that case actually even the current definition of traverse would break.

@joroKr21
Copy link
Member Author

Maybe the alternative is to provide an inject argument to fold to be able to go back to the sum - WDYT about that?

@milessabin
Copy link
Member

Maybe the alternative is to provide an inject argument to fold to be able to go back to the sum - WDYT about that?

I'm not keen on that, because we want the erased operation to be just a cast.

Unions are still super types.

This is right of course, so I don't actually have any objections here.

@milessabin milessabin self-requested a review October 11, 2021 13:17
Copy link
Member

@milessabin milessabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@joroKr21 joroKr21 merged commit 995b14f into typelevel:main Oct 11, 2021
@joroKr21 joroKr21 deleted the bounds branch October 11, 2021 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants