Skip to content

Instantly share code, notes, and snippets.

@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]

Suppose we want to lift an OptionT[List, Int] into a ReaderT[OptionT[List, _], String, Int]. The nice way (liftReaderT) currently doesn't work:

scala> List(1, 2, 3).liftM[OptionT].liftReaderT[String]
<console>:14: error: could not find implicit value for parameter F0: scalaz.UnapplyCo[scalaz.Monad,scalaz.OptionT[List,Int]]
              List(1, 2, 3).liftM[OptionT].liftReaderT[String]
                                 ^
<console>:14: error: value liftReaderT is not a member of scalaz.OptionT[List,Int]
              List(1, 2, 3).liftM[OptionT].liftReaderT[String]
 ^