Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a Monad Transformer when Disjunction is the outermost container?

val vLInts = (1 to 10).toList.right[String]

for {
  i <- ListT(vLints)
  _ = println(i)
} yield i

//error: no type parameters for method apply:(underlying: M[List[A]])scalaz.ListT[M,A] in object ListT exist so that it can be applied to arguments (scalaz.\/[String,List[Int]])

The problem here is that a disjunction \/[A, B] has 2 generics and therefore isn't a Monad. When i make a type alias

type Attempt[A] = \/[String, A]

it succeeds, because I've held the left side fixed and I now have Monad. How can I get my Monad Transformer to work if the outermost type is a Disjunction, without resorting to type aliasing?

like image 653
jordan3 Avatar asked Nov 02 '22 03:11

jordan3


1 Answers

for{
i <- ListT[({type l[+a] = String \/ a})#l,Int](vLints)
_ = println(i)
} yield i

Apparently, the answer was a type lambda. It's not pretty but it works.

like image 81
jordan3 Avatar answered Nov 15 '22 07:11

jordan3