Skip to content

Instantly share code, notes, and snippets.

@AitorATuin
Created October 13, 2012 21:55
Show Gist options
  • Select an option

  • Save AitorATuin/3886285 to your computer and use it in GitHub Desktop.

Select an option

Save AitorATuin/3886285 to your computer and use it in GitHub Desktop.
Enabling Pimp Types on abstract methods in trait
package com.sbs.oraculus.loserishoraculus
trait LoserishOraculus {
def showMeTheAnswer:String
}
ackage com.sbs.oraculus
package notsoloserishoraculus
import loserishoraculus._
import Query.DeepThought
trait Oraculus
trait WisdomOraculus[R] {
def answer:String
}
trait NotSoLoserishOraculus[R] extends LoserishOraculus {
implicit val delphos: WisdomOraculus[Oraculus] = new WisdomOraculus[Oraculus] {
def answer = "I dont know the answer, i'm a loserish oracle!"
}
override def showMeTheAnswer():String = {
println("Delphos answering")
delphos.answer
}
def showMeTheAnswer(implicit i:WisdomOraculus[R]):String
}
object NewOraculusQuery {
val query = new NotSoLoserishOraculus[DeepThought] {
def showMeTheAnswer(implicit i:WisdomOraculus[DeepThought]):String = i.answer
}
}
package com.sbs.oraculus
import notsoloserishoraculus._
import notsoloserishoraculus.NewOraculusQuery._
object Query {
trait DeepThought extends Oraculus
implicit val deepThought = new WisdomOraculus[DeepThought] {
def answer = "The answer is 42"
}
def main(args:Array[String]) = println(query.showMeTheAnswer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment