Created
November 9, 2009 07:14
-
-
Save retronym/229756 to your computer and use it in GitHub Desktop.
This file contains 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
// 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