-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 MFunctor type class for mapping monad morphisms over monad transformers #1492
Conversation
Current coverage is 91.63% (diff: 0.00%)@@ master #1492 diff @@
==========================================
Files 244 244
Lines 3621 3633 +12
Methods 3502 3513 +11
Messages 0 0
Branches 119 120 +1
==========================================
Hits 3329 3329
- Misses 292 304 +12
Partials 0 0
|
As coded, this is also known as |
@edmundnoble thanks for your comments, I agree that without codifying the constraints, it really is more general than my original description of the type class - that is that it's a functor in the category of monads, rather it's a functor in the category of endofunctors of scala types, if we view all (* -> *) kinded types as functors. I'm just not sure how far this generalisation should be taken, what do you think? I'm now tempted to just leave it as it is, and introduce a constraint member to the class, which then makes it possible to write out all instances of interest (monad transformers, comonad transformers, free monads, etc) |
|
@xuwei-k thanks for linking those in, the mmorph library is indeed where I picked up the name from, although I am planning to take a somewhat different direction here |
There are two shapes of this possible transformation type class, discussed here. |
@kailuowang This is no longer planned to be included in cats-mtl. I don't see a use for it, but I'd be interested in hearing of one. As is we'd need three variants, for mapping natural transformations, applicative homomorphisms, and monad homomorphisms. |
related #1713 |
What is the usecase of mapping natural transformations though? |
@edmundnoble, as mentioned in this ticket, one use case is to abstract out "changing the underlying monad of a monad transformer using a natural transformation." |
Right, I'm asking for a concrete instantiation of such a use case. I don't think such a thing is useful generically; though it's useful for specific monad transformers, inductive usage cannot actually change the monad inside a transformer. |
I realized that myself after I wrote #1812. The only immediate benefit seems to be the conformity of the API. It creates a consistent way mapNT to do such inner monad swap. In the long run, it proves that these things (see the instances in #1812) are indeed endofunctors in the category of endofunctors. Maybe someone will discover generic usage of it in the future? Like we didnt know the FunctorK is useful until we discovered final tagless encoding. Of course such speculation isn't a good reason to add it now to cats.core, but the API conformity might be. |
continued on #1815, closing for now. |
WIP:
This generalises the notion of changing the underlying monad of a monad transformer using a natural transformation.
I opened the PR to have some feedback/discussion on the following points: