Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created April 8, 2012 10:59
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 milessabin/2336624 to your computer and use it in GitHub Desktop.
Save milessabin/2336624 to your computer and use it in GitHub Desktop.
Name this idiom. Is it novel?
// K ~?> V witnesses the existence of a natural transformation between K and V
class ~?>[K[_], V[_]] {
class λ[KT, VT] // Witness K ~?> V at a particular K[T], V[T]
}
object ~?> {
// To instantiate the first-order witness we need a value of the
// higher-kinded witness, so we depend on it implicitly
implicit def witness[K[_], V[_], T](implicit rel : K ~?> V) = new rel.λ[K[T], V[T]]
implicit def rel[K[_], V[_]] = new (K ~?> V)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment