forked from typelevel/kind-projector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue80.scala
More file actions
21 lines (18 loc) · 802 Bytes
/
issue80.scala
File metadata and controls
21 lines (18 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
trait ~~>[A[_[_]], B[_[_]]] {
def apply[X[_]](a: A[X]): B[X]
}
trait Bifunctor[F[_[_[_]], _[_[_]]]] {
def bimap[A[_[_]], B[_[_]], C[_[_]], D[_[_]]](fab: F[A, B])(f: A ~~> C, g: B ~~> D): F[C, D]
}
final case class Coproduct[A[_[_]], B[_[_]], X[_]](run: Either[A[X], B[X]])
object Coproduct {
def coproductBifunctor[X[_]]: Bifunctor[Coproduct[*[_[_]], *[_[_]], X]] =
new Bifunctor[Coproduct[*[_[_]], *[_[_]], X]] {
def bimap[A[_[_]], B[_[_]], C[_[_]], D[_[_]]](abx: Coproduct[A, B, X])(f: A ~~> C, g: B ~~> D): Coproduct[C, D, X] =
abx.run match {
case Left(ax) => Coproduct(Left(f(ax)))
case Right(bx) => Coproduct(Right(g(bx)))
}
}
def test[X[_]]: Bifunctor[({ type L[F[_[_]], G[_[_]]] = Coproduct[F, G, X] })#L] = coproductBifunctor[X]
}