Skip to content

Instantly share code, notes, and snippets.

@retronym
Created November 7, 2009 13:00
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save retronym/228673 to your computer and use it in GitHub Desktop.
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
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