-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Inheritance between optics #1088
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…Scala 2-3 differences
This was referenced Feb 22, 2021
Using def modifyF[F[_]: Functor](f: A => F[B])(s: S)(implicit dummy: DummyImplicit): F[T] =
Functor[F].map(f(get(s)))(reverseGet) But then it would make delegating from the |
kenbot
approved these changes
Feb 23, 2021
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.
Reading the discussion and the code, this looks ok to me, as far as I understand the issues.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consistent method location
Fold
andGetter
definedeach
,index
, ... as class methods while other optics defined these methods as extension methods. As a result,Getter#each
took precedence overLens#each
.composeXXX
Inheritance introduced regressions in type inference. This is because inheritance overloaded some methods. For example, the code below compiles without inheritance but fails afterward:
The compiler says that their are two overloaded versions of
composePrism
. This makes sense if you look at the signature ofGetter
andPLens
.Note that
composePrism
forFold
has 3 type parameters while the same method forPOptional
has 2 type parameters.I thought that variance could help:
Unfortunately, it still overlaod
composePrism
.So I moved all the
composeXXX
and symbolic operator to extension method, this way they don't overlaod anything.modifyF
I found a limitation of Scala with regards to inheritance. As @tpolecat mentioned it, Scala doesn't accept narrowing on inputs. This means we can't do:
The only solution I could come up with is to rename
modifyF
inTraversal
,Optional
andPrism
tomodifyA
and keepmodifyF
forLens
andIso
. If somone finds a better name, we can rename it later. Thanks to @joroKr21 for the suggestion.