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. |
djspiewak
left a comment
There was a problem hiding this comment.
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
mapKmethods to require constraints on the target effect, not the original effect.