Created
October 7, 2013 19:22
-
-
Save anonymous/6873422 to your computer and use it in GitHub Desktop.
Comparison of the straightforward embedding of a basic tenet of category theory in Scala vs Haskell.
This file contains hidden or 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
yonedaLemma = Iso (flip fmap) ($ id) |
This file contains hidden or 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
def yonedaLemma[F[_]:Functor, A]: F[A] <=> (({type λ[α] = A => α })#λ ~> F) = | |
new (F[A] <=> (({type λ[α] = A => α })#λ ~> F)) { | |
def to(fa: F[A]) = new (({type λ[α] = A => α })#λ ~> F) { | |
def apply[R](f: A => R) = Functor[F].map(fa)(f) | |
} | |
def from(f: (({type λ[α] = A => α })#λ ~> F)) = f(a => a) | |
} |
How is the affected by recent scala, typelevel scala, or dotty features?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also to be fair, the Haskell version should have a type annotation because the Scala version does: