Skip to content

Instantly share code, notes, and snippets.

@tpolecat
Created February 12, 2013 19:48
Show Gist options
  • Save tpolecat/4772802 to your computer and use it in GitHub Desktop.
Save tpolecat/4772802 to your computer and use it in GitHub Desktop.
import annotation.implicitNotFound
@implicitNotFound(msg = "This message can never appear!")
trait ~>[A, B] { self =>
def apply(a: A): B
def invert(b: B): A = inverse.apply(b)
def inverse: B ~> A = new ~>[B, A] {
def apply(b: B) = self.invert(b)
override def invert(a: A) = self(a)
}
}
trait Init[A, B] extends (A ~> B)
implicit def inverseOf[A, B](implicit forward: Init[A, B]): B ~> A = forward.inverse
implicit def i2d: Init[Int, Double] = ???
implicitly[Int ~> String] // "This message can never appear!"
implicitly[String ~> Int] // "This message can never appear!"
implicitly[Int ~> Double]
implicitly[Double ~> Int] // conjured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment