Skip to content

Instantly share code, notes, and snippets.

@japgolly
Created March 12, 2014 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japgolly/9502607 to your computer and use it in GitHub Desktop.
Save japgolly/9502607 to your computer and use it in GitHub Desktop.
Coyoneda natural transformations
object ForScalaz {
type CoyonedaF[F[_]] = ({type A[α] = Coyoneda[F, α]})
def FG_to_CFG[F[_], G[_] : Functor, A](t: F ~> G): (CoyonedaF[F]#A ~> G) = {
type CF[A] = Coyoneda[F, A]
type CG[A] = Coyoneda[G, A]
val m: (CF ~> CG) = FG_to_CFCG(t)
val n: (CG ~> G) = CF_to_F
val o: (CF ~> G) = n compose m
o
}
def FG_to_CFCG[F[_], G[_]](f: F ~> G): (CoyonedaF[F]#A ~> CoyonedaF[G]#A) =
new (CoyonedaF[F]#A ~> CoyonedaF[G]#A) {
def apply[X](c: CoyonedaF[F]#A[X]): CoyonedaF[G]#A[X] = c.trans(f)
}
def CF_to_F[F[_] : Functor]: (CoyonedaF[F]#A ~> F) =
new (CoyonedaF[F]#A ~> F) {
def apply[X](c: CoyonedaF[F]#A[X]): F[X] = c.run
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment