Created
April 4, 2012 07:14
-
-
Save raymondtay/2299422 to your computer and use it in GitHub Desktop.
implicit funkiness
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
trait S[M[_]] { | |
def doS[I](input: I) : I | |
} | |
object S { | |
implicit def convert2S(x : Int) : S[List] = new S[List] { | |
def doS[I](input: I) : I = { println("convert2S: returning 'input'..."); input } | |
} | |
implicit object SLike extends S[List] { def doS[I](i: I) : I = i; def doSLikeStuff[I <: List[_]](l: I) = l(0) } | |
implicit object SLike2 extends S[Set] { def doS[I](i: I) : I = i; def doSLikeStuff[I <: Set[_]](l: I) = l.headOption } | |
} | |
object DemoImplicitlyPredef extends App { | |
val s: S[List] = 5 // implicit conversion should happen here | |
println("This is S -> " + s) | |
demo[Set]("woot! ftw!") | |
demo("woot! woo yeah!")(s) | |
def demo[M[_]](s: String)(implicit ss: S[M]) = { | |
println("demo ->"+ ss.doS(s) ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment