Created
October 10, 2014 15:39
-
-
Save justjoheinz/bcbaa4a4e69e61a1aa96 to your computer and use it in GitHub Desktop.
Attempt to get the coproduct of natural transformations working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait NaturalTransformation[-F[_], +G[_]] { | |
self => | |
def apply[A](fa: F[A]): G[A] | |
def compose[E[_]](f: E ~> F): E ~> G = new (E ~> G) { | |
def apply[A](ea: E[A]) = self(f(ea)) | |
} | |
def or[H[_]](f: H ~> G): ({type f[x] = Coproduct[F, H, x]})#f ~> G = | |
new (({type f[x] = Coproduct[F, H, x]})#f ~> G) { | |
def apply[A](c: Coproduct[F, H, A]): G[A] = c.run match { | |
case -\/(fa) => self(fa) | |
case \/-(ha) => f(ha) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment