Skip to content

Instantly share code, notes, and snippets.

@retronym
Created November 9, 2009 07:14
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 retronym/229756 to your computer and use it in GitHub Desktop.
Save retronym/229756 to your computer and use it in GitHub Desktop.
// Named <::< to clearly distinguish from Predef.<:<
sealed abstract class <::<[-From, +To] extends (From => To)
object <::< {
implicit def conforms[A]: A <::< A = new (A <::< A) {def apply(x: A) = x}
}
sealed abstract class =:=[From, To] extends (From => To)
object =:= {
implicit def tpEquals[A]: A =:= A = new (A =:= A) {def apply(x: A) = x}
}
sealed abstract class <%<[-From, +To] extends (From => To)
object <%< {
implicit def conformsOrViewsAs[A <% B, B]: A <%< B = new (A <%< B) {def apply(x: A) = x}
}
trait A
trait B
implicit def AToB(a: A): B = new B {}
println("(implicitly[Int =:= Int], implicitly[Int <::< Any], implicitly[A <%< B]) = " +
(implicitly[Int =:= Int], implicitly[Int <::< Any], implicitly[A <%< B]))
//object Predef {
implicit def identity[A](a: A): A = a
//}
println("(implicitly[Int => Int], implicitly[Int => Any], implicitly[A => B]) = " +
(implicitly[Int => Int], implicitly[Int => Any], implicitly[A => B]))
// Isomorphism between A => B and A <%< B
println("(implicitly[A => B], implicitly[A <%< B]) = " +
(implicitly[A => B], implicitly[A <%< B]))
// Compile Errors:
// implicitly[Int =:= Any] // error: could not find implicit value for parameter e: this.=:=[Int,Any]
// implicitly[A <::< B] // error: could not find implicit value for parameter e: this.<::<[this.A,this.B]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment