Skip to content

Instantly share code, notes, and snippets.

@raymondtay
Created April 4, 2012 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raymondtay/2299422 to your computer and use it in GitHub Desktop.
Save raymondtay/2299422 to your computer and use it in GitHub Desktop.
implicit funkiness
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