1
votes

Some definition of Monad Transformers in cats.

EitherT[F[_], A, B] is a lightweight wrapper for F[Either[A, B]] that makes it easy to compose Eithers and Fs together. To use EitherT, values of Either, F, A, and B are first converted into EitherT, and the resulting EitherT values are then composed using combinators.

OptionT[F[_], A] is a light wrapper on an F[Option[A]]. Speaking technically, it is a monad transformer for Option, but you don’t need to know what that means for it to be useful. OptionT can be more convenient to work with than using F[Option[A]] directly.

I understand the concept, even saw some interesting talk about it: Monad transformers down to earth by Gabriele Petronella

I understand the Reader Monad, and how Kleisli is just a generalization.

What i do not understand is the statement bellow, that says that it is a monad transformer. What are we stacking exactly ? I don't see 2 monad being stacked here ....

Kleisli can be viewed as the monad transformer for functions. Recall that at its essence, Kleisli[F, A, B] is just a function A => F[B], with niceties to make working with the value we actually care about, the B, easy. Kleisli allows us to take the effects of functions and have them play nice with the effects of any other F[_].

Any thoughts ?

1

1 Answers

4
votes

Monad transformer EitherT[F[_], A, B] (a wrapper for F[Either[A, B]]) appears when we consider composition of two monads: F (outer monad) and Either[A, ?] (inner monad).

Monad transformer OptionT[F[_], A] (a wrapper for F[Option[A]]) appears when we consider composition of two monads: F (outer monad) and Option (inner monad).

Monad transformer Kleisli[F, A, B] (a wrapper for A => F[B]) appears when we consider composition of two monads: A => ? (outer monad) and F (inner monad).