5
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]])

这里的问题是析取\/[A, B]有 2 个泛型,因此不是 Monad。当我制作类型别名时

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

它成功了,因为我已经固定了左侧,现在我有了 Monad。如果最外面的类型是析取,我怎样才能让我的 Monad Transformer 工作,而不使用类型别名?

4

1 回答 1

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

显然,答案是 lambda 类型。它不漂亮,但它有效。

于 2014-03-17T16:06:03.543 回答