This question is inspired by the feedback given to my previous question
Scalaz
provides a wrapper class Kleisli[M[_], A, B]
for a function A => M[B]
.
Kleisli[M[_], A, B]
is a semigroup if M[_]
is a semigroup. Suppose that M[_]
is a functor. Is it correct that Kleisli
is a functor too ? What if M[_]
is an applicative or monad ?
The fully unapplied Kleisli
isn't much of anything—it has kind (* -> *) -> * -> * -> *
, and I don't know of any meaningful type classes for that kind.
If you have a monad for a type constructor F[_]
, though, then Kleisli[F, ?, ?]
is an Arrow
(which is a type class for things of kind * -> * -> *
).
Similarly, if F[_]
has a functor instance, then Kleisli[F, A, ?]
has a functor instance for any specific A
. In fact the same thing works for applicative functors and monads—have an instance of any of them for F[_]
and you have an instance for Kleisli[F, A, ?]
as well.
Lastly, if you have a semigroup (or monoid) for F[B]
, then Kleisli[F, A, B]
is a semigroup (or monoid) for any A
.