Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Scalaz 7's EitherT with liftM

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).

like image 432
Hugh Avatar asked Oct 12 '12 07:10

Hugh


1 Answers

There doesn't appear to be a better way to handle multi-argument type constructors in general, but in the specific case of EitherT, we can use 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
like image 81
Hugh Avatar answered Nov 16 '22 03:11

Hugh