私は a を持っていて、Seq[R]
これを a に分割したいのですが、これをコーディングしているときに、seq のタプルにTuple2[Seq[E], Seq[S]]
カスタムを使用できるという事実について考え、演習としてこれをコーディングしようとしました。Bifunctor
import scalaz.Bifunctor
type MyType[E, S] = (Seq[E], Seq[S])
case class MyVali[E, S](tp: (Seq[E], Seq[S]))(implicit bifunctor: Bifunctor[MyType]) {
def bimap[C, D](f: (E) => C, g: (S) => D): (Seq[C], Seq[D]) =
bifunctor.bimap(tp)(f, g)
def leftMap[C](f: (E) => C): (Seq[C], Seq[S]) =
bifunctor.leftMap(tp)(f)
def rightMap[D](g: (S) => D): (Seq[E], Seq[D]) =
bifunctor.rightMap(tp)(g)
}
val myValBifunctorInstance = new Bifunctor[MyType] {
override def bimap[A, B, C, D](fab: (Seq[A], Seq[B]))(f: (A) => C, g: (B) => D): (Seq[C], Seq[D]) =
(fab._1.map(f), fab._2.map(g))
}
MyVali((Seq.empty[String], Seq.empty[Int]))(myValBifunctorInstance).bimap(a => a, b => b)
これは正常に動作しますが、何らかの理由で、このすべてをコンパイルするためにパラメーター化された型エイリアスを宣言する必要type MyType[E, S] = (Seq[E], Seq[S])
がありました。
def myValBimap[E, S] = new Bifunctor[Tuple2[Seq[E], Seq[S]]] {
override def bimap[A, B, C, D](fab: (A, B))(f: (A) => C, g: (B) => D): (C, D) = ???
}
[エラー] ... (Seq[E], Seq[S]) は型パラメーターを取りません。予想: 2
[エラー] def myValBimap[E, S] = new Bifanctor[Tuple2[Seq[E], Seq[S]]] {
そのような型エイリアスが定義されている場合、コンパイラは 2 型サスペンション (ネストされたラムダ型のようなものでしょうか?) を作成していますか?