Created
December 16, 2009 10:58
-
-
Save retronym/257748 to your computer and use it in GitHub Desktop.
How to Chain Implicit Conversions (aka Views) in Scala
This file contains hidden or 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
class T { | |
val t = "T" | |
} | |
class U | |
class V | |
object T { | |
implicit def UToT[UU <% U](u: UU) = new T | |
} | |
object U { | |
implicit def VToU[VV <% V](v: VV) = new U | |
} | |
object V { | |
implicit def StringToV(s: String) = new V | |
} | |
object Test { | |
import T._ | |
import U._ | |
import V._ | |
"": T | |
// compiles to: | |
// (T.UToT[java.lang.String]("")({ | |
// ((v: java.lang.String) => U.VToU[java.lang.String](v)({ | |
// ((s: String) => V.StringToV(s)) | |
// })) | |
// }): T) | |
"".t // this also triggers the conversion. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment