Created
October 13, 2012 21:55
-
-
Save AitorATuin/3886285 to your computer and use it in GitHub Desktop.
Enabling Pimp Types on abstract methods in trait
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
| package com.sbs.oraculus.loserishoraculus | |
| trait LoserishOraculus { | |
| def showMeTheAnswer:String | |
| } |
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
| 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 | |
| } | |
| } |
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
| 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