-
Notifications
You must be signed in to change notification settings - Fork 557
Refactor Ref#mapK
to take Functor[G]
constraint instead of Functor[F]
#4115
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
Refactor Ref#mapK
to take Functor[G]
constraint instead of Functor[F]
#4115
Conversation
Ref#mapK
to take Functor[G]
constraint instead of `Functor[F]Ref#mapK
to take Functor[G]
constraint instead of Functor[F]
Out of curiosity: why is this best practice? And is it worth documenting? (Not in this PR, but maybe a followup.) |
The general pattern is that we collect constraints at creation, not at use-site. In fact, if we made this an abstract method, we wouldn't need to collect a use-site constraint on the method. In this case, this is a use-site in |
Fascinatingly, this is a thing that has a bit of nuance. For example, if you have a functional I still essentially agree with what you're saying but I think this is an area that has defied hard and fast idioms. |
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.
This does result in some theoretical compatibility breakage if someone is overriding mapK
to do something weird. I'm pretty comfortable saying that's unsupported behavior though, and the deprecation warning will trigger.
That invites the possibility of using the same set with inconsistent ordering in different places. |
Yes indeed, which was exactly why I argued in favor of capturing it at point of creation in the past. Basically, incoherence causes all sorts of these types of weirdnesses. |
I'm thinking of a type class: trait FunctorK[T[_[_]]] {
def mapK[F[_]: Functor, G[_]](tf: T[F])(fk: F ~> G): T[G]
} because I need it for higher-kinded data but I don't know what to call it and I'm still not convinced the constraint should be on
This all sounds a bit hand-wavy. I'm not even sure what those sentences mean. It's a use-site of going from |
Best practice is for
mapK
methods to require constraints on the target effect, not the original effect.