10

If I have a monad transformer type taking two type arguments, I can use liftM to lift values into the transformed monad:

scala> val o = 1.point[List].liftM[OptionT]
o: scalaz.OptionT[List,Int] = OptionT(List(Some(1)))

However if I try the same thing with EitherT it seems like I must use a type alias (or a type 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

What's the proper way to do this? Ideally inferring the type argument for liftM using the expected type of the expression (something like val blah: EitherT[List, String, Int] = 1.point[List].liftM).

4

1 に答える 1

8

一般に、複数引数の型コンストラクターを処理するより良い方法はないようですが、特定のケースでは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@12fa8880
于 2012-10-31T04:08:28.823 に答える