Skip to content

Instantly share code, notes, and snippets.

@labra
Last active September 1, 2016 08:13
Show Gist options
  • Save labra/e6346b956a8957fd8547ef9e93fee5df to your computer and use it in GitHub Desktop.
Save labra/e6346b956a8957fd8547ef9e93fee5df to your computer and use it in GitHub Desktop.
Example of monad transformer stack...question on how to lift local
package examples
import cats._, data._
import cats.implicits._
object local {
type Env = Map[String,Int]
type MyState = List[Int]
type S[A] = EitherT[StateT[WriterT[Kleisli[List,Env,?],String,?],MyState,?], String, A]
// How can I define localS
def localS[A](f: Env => Env)(sa: S[A]): S[A] = ???
// I was able to define getEnv using several lifts
def getEnv: S[Env] = {
liftS(Kleisli.ask[List,Env])
}
def liftS[A](c: Kleisli[List,Env,A]): S[A] =
c.liftT[λ[(F[_], A) => WriterT[F, String, A]]].
liftT[λ[(F[_], A) => StateT[F, MyState, A]]].
liftT[λ[(F[_], A) => EitherT[F, String, A]]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment