Matthew Pickering - 2 months ago 28

Scala Question

I have been trying simple Monad Transformers where I have for comprehensions involving

`M[F[A]]`

`M`

`F`

`M[F[A]]`

`M[S[A]]`

`S`

For example:

`val a: Future[List[Int]] = ...`

val b: Future[Option[Int]] = ...

`a`

`ListT[Future, Int]`

`b`

`OptionT[Future, Int]`

Answer

Monad Transformers help you in composing two values of type `F[G[X]]`

.

In other terms, monad transformers work with `F[G[X]]`

because they leverage the fact that you know how to compose two `G[X]`

if `Monad[G]`

exists.

Now, in case of `F[G[X]`

and `F[H[X]]`

, even if you state that `G`

and `H`

have `Monad`

instances, you still don't have a general way of composing them.

I'm afraid composing `F[G[X]]`

and `F[H[X]]`

has no general solution with monad transformers.