Skip to content

Instantly share code, notes, and snippets.

@debasishg
Forked from anonymous/Haskell
Created November 3, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debasishg/12c28a35b28d3c16ad00d1a628767c91 to your computer and use it in GitHub Desktop.
Save debasishg/12c28a35b28d3c16ad00d1a628767c91 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.
yonedaLemma = Iso (flip fmap) ($ id)
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment