Created
November 7, 2009 13:00
-
-
Save retronym/228673 to your computer and use it in GitHub Desktop.
Scala 2.8 implicit prioritisation, as discussed in: http://www.scala-lang.org/sid/7
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
object Low { | |
def low = "object Low" | |
def shoot = "missed!" | |
} | |
object High { | |
def high = "object High" | |
def shoot = "bulls eye!" | |
} | |
trait LowPriority { | |
implicit def intToLow(a: Int): Low.type = Low | |
} | |
object HighPriority extends LowPriority { | |
implicit def intToHigh(a: Int): High.type = High | |
} | |
import HighPriority._ | |
val a: Int = 1 | |
print((a.low, a.high, a.shoot)) // (object Low,object High, bulls eye!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment