0

だから私はこの署名を持つ高価なメソッドを持っています

def func(param: Int): \/[String, Int]

パラメータと戻り値のリストをループしようとしています\/[String, List[Int]]が、メソッドが戻るたびにループを停止します-\/

私はこれを思いつきます:

scala> def func(i: Int) = {
     |   if( i > 1 ) { println{"!!"} ;"error".left[Int]}
     |   else i.right[String]
     | }
func: (i: Int)scalaz.\/[String,Int]

scala> val toList = (dis: scalaz.\/[String,Int]) => {dis.map(i => List(i))}
toList: scalaz.\/[String,Int] => scalaz.\/[String,List[Int]] = <function1>

scala> val composed = (func _) andThen toList
composed: Int => scalaz.\/[String,List[Int]] = <function1>

scala> (1 to 3).toList.foldLeftM(List[Int]().right[String]){(dis, i) =>
     |   for{
     |     a <- dis
     |     b <- composed(i)
     |   } yield a |+| b
     | }
<console>:17: error: no type parameters for method foldLeftM: (f: (scalaz.\/[String,List[Int]], Int) => G[scalaz.\/[String,List[Int]]])(implicit M: scalaz.Monad[G])G[scalaz.\/[String,List[Int]]] exist so that it can be applied to arguments ((scalaz.\/[String,List[Int]], Int) => scalaz.\/[String,List[Int]])
 --- because ---
argument expression's type is not compatible with formal parameter type;
 found   : (scalaz.\/[String,List[Int]], Int) => scalaz.\/[String,List[Int]]
 required: (scalaz.\/[String,List[Int]], Int) => ?G[scalaz.\/[String,List[Int]]]

              (1 to 2).toList.foldLeftM(List[Int]().right[String]){(dis, i) =>
                                       ^
<console>:17: error: type mismatch;
 found   : (scalaz.\/[String,List[Int]], Int) => scalaz.\/[String,List[Int]]
 required: (scalaz.\/[String,List[Int]], Int) => G[scalaz.\/[String,List[Int]]]
              (1 to 2).toList.foldLeftM(List[Int]().right[String]){(dis, i) =>
                                                                            ^

ここは何ですか?G[_]の正しい結果の型はfoldLeftM何ですか?

4

1 に答える 1