trait ApplicativeIdV[A] extends Ops[A] { def point(implicit F: Applicative[F]): F[A] = Applicative[F].point(self) ... trait OptionTFunctions { def optionT[M[_]] = new (({type λ[α] = M[Option[α]]})#λ ~> ({type λ[α] = OptionT[M, α]})#λ) { def apply[A](a: M[Option[A]]) = new OptionT[M, A](a) } ... final class MonadOps[F[_],A] private[syntax](val self: F[A])(implicit val F: Monad[F]) extends Ops[F[A]] { ////
def liftM[G[_[_], _]](implicit G: MonadTrans[G]): G[F, A] = G.liftM(self) ...
1 val prg: Result[String] = for { 2 s1 <- OptionT.optionT(getString.point[Error]) 3 s0 <- OptionT(none[String].point[Error]) 4 s2 <- "World,".point[Result] 5 s3 <- getResult.liftM[OptionT] 6 } yield s1+s2+s3 //> prg : Exercises.monadtxns.Result[String] = OptionT(\/-(None))
7 prg.run //> res0: Exercises.monadtxns.Error[Option[String]] = \/-(None)
1 val prg: Result[String] = for { 2 s1 <- OptionT.optionT(getString.point[Error]) 3 s0 <- OptionT("Catch Error!".left: Error[Option[String]]) 4 s2 <- "World,".point[Result] 5 s3 <- getResult.liftM[OptionT] 6 } yield s1+s2+s3 //> prg : Exercises.monadtxns.Result[String] = OptionT(-\/(Catch Error!))
7 prg.run //> res0: Exercises.monadtxns.Error[Option[String]] = -\/(Catch Error!)
type StringEither[A] = String \/ A type StringEitherT[M[_],A] = EitherT[M,String,A] type IntState[A] = State[Int,A] type IntStateT[M[_],A] = StateT[M,Int,A] type StateEither[A] = StringEitherT[IntState,A] type StateEitherOption[A] = OptionT[StateEither,A]
//常量升格
val m: StateEitherOption[Int] = 3.point[StateEitherOption] //> m : Exercises.monad_txnfm.StateEitherOption[Int] = OptionT(EitherT(scalaz.p //| ackage$StateT$$anon$1@4f638935)) //option类升格
val o: Option[Int] = 3.some //> o : Option[Int] = Some(3)
val o1: StateEither[Option[Int]]= o.point[StateEither] //> o1 : Exercises.monad_txnfm.StateEither[Option[Int]] = EitherT(scalaz.packag //| e$StateT$$anon$1@694abbdc)
val o2: StateEitherOption[Int] = OptionT.optionT(o1) //> o2 : Exercises.monad_txnfm.StateEitherOption[Int] = OptionT(EitherT(scalaz. //| package$StateT$$anon$1@694abbdc)) //val o2: OptionT[StateEither,Int] = OptionT.optionT(o1) //either类升格
val e: StringEither[Int] = 3.point[StringEither] //> e : Exercises.monad_txnfm.StringEither[Int] = \/-(3)
val e1: IntState[StringEither[Int]] = e.point[IntStat