如何在Scalaz中组合Monad变换器

3
如何使这个编译通过,或者做类似的事情?
import scala.concurrent.Future
import scalaz._
import Scalaz._

val ee: Future[Unit \/ Option[Int]] = Future(\/-(Option(1)))
OptionT.optionT(EitherT.eitherT(ee))

你在这里尝试建模什么?一个失败的未来和左侧带有 () 或右侧带有 None 成功的未来有何不同? - Travis Brown
这只是一个简化的例子。您可以替换任何类型,而不是Unit和Int。 - Denis Mikhaylov
1个回答

0

你只需要明确地传递类型(同时 OptionT.optionT 稍微做了些不同的事情):

//could use a type lambda, but this is (IMO) slightly clearer
type FutureEither[A] = EitherT[Future, Unit, A]
new OptionT[FutureEither, Int](EitherT.eitherT[Future, Unit, Option[Int]](ee))

(我应该提一下我的scalaz-transfigure库,它是一个稍微轻便、更具推理性的方法去完成与单子变换器相同的事情;不过它还没有非常成熟)


我认为OptionT#optionT只是将OptionT#apply实现为自然变换,以避免重复包含的类型:optionT[FutureEither](EitherT(ee)) - Hugh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接