如果我有一个带有两个类型参数的monad转换器类型,我可以使用liftM将值提升到转换后的monad中:
scala> val o = 1.point[List].liftM[OptionT]
o: scalaz.OptionT[List,Int] = OptionT(List(Some(1)))然而,如果我用EitherT做同样的事情,似乎我必须使用一个类型别名(或一个lambda类型):
scala> val e = 1.point[List].liftM[({type l[a[+_],b] = EitherT[a, String, b]})#l]
e: scalaz.EitherT[List,java.lang.String,Int] = scalaz.EitherTFunctions$$anon$14@3f8905ca这样做的正确方法是什么?理想情况下,使用表达式的预期类型(类似于val blah: EitherT[List, String, Int] = 1.point[List].liftM)来推断liftM的类型参数。
发布于 2012-10-31 12:08:29
一般来说,似乎没有更好的方法来处理多参数类型的构造函数,但在EitherT的特定情况下,我们可以使用EitherT.right
scala> val o: EitherT[List, String, Int] = EitherT.right(1.point[List])
o: scalaz.EitherT[List,String,Int] = scalaz.EitherTFunctions$$anon$14@12fa8880https://stackoverflow.com/questions/12853879
复制相似问题