Last active
September 1, 2016 08:13
-
-
Save labra/e6346b956a8957fd8547ef9e93fee5df to your computer and use it in GitHub Desktop.
Example of monad transformer stack...question on how to lift local
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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