Cats: Add FunctorK trait

Created on 12 Jan 2019  Â·  4Comments  Â·  Source: typelevel/cats

There are several transformers and data types in cats and associated libraries that are parameterised on a kind-1 type F[_] and a kind-0 type parameter A. For convenience, I called them the _effect_ type and the _value_ type, respectively. Some of these data types are Nested, EitherT, OptionT, OneAnd, Kleisli, Free.

In cats-tagless project defines a trait _FunctorK_, for types that provide a mapK method, which could be defined as follows:

trait FunctorK[A[_[_]]]  {
  def mapK[F[_], G[_]](af: A[F])(fk: F ~> G): A[G]
}

The proposal of this issue is to bring the definition of this FunctorK type-class into the core library, given that it would abstract an operation already in the library.

Most helpful comment

@djspiewak thanks for the helpful summarization of the problem. I am going to refer to it at the FunctorK definition in cats-tagless.

All 4 comments

@diesalbla FWIW, I don't think we need to close this immediatly, we could discuss this again :)

As a quick intuition as to why this has historically been complicated…

Higher-kinded arities get complicated very quickly. The FunctorK defined in the OP issue here is pretty intuitive, and there are a lot of inhabitants, but it isn't strictly the higher-order version of Functor in the way that InjectK is the higher-order version of Inject, or MonoidK is the higher-order version of Monoid. There are very valid reasons why you would want a different signature (see #1815), but that sort of signature in turn rules out some nice applications of the OP's signature, particularly if you care at all about type inference.

It's kind of a mess. Poly kinds make this much nicer. Also if Scala had a kind system which didn't encode arities in the way it does, that would also make these sorts of things easier to generalize (since we wouldn't have to carry an explicit first-order-kinded type along as we climb the universes).

@djspiewak thanks for the helpful summarization of the problem. I am going to refer to it at the FunctorK definition in cats-tagless.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kailuowang picture kailuowang  Â·  5Comments

Atry picture Atry  Â·  5Comments

peterneyens picture peterneyens  Â·  5Comments

durban picture durban  Â·  4Comments

mcanlas picture mcanlas  Â·  4Comments