Skip to content

Instantly share code, notes, and snippets.

@sshark
Last active November 10, 2015 13:31
Show Gist options
  • Select an option

  • Save sshark/2185fe809dc31f2f9123 to your computer and use it in GitHub Desktop.

Select an option

Save sshark/2185fe809dc31f2f9123 to your computer and use it in GitHub Desktop.
Exhibit how "type" can be used with "implicit"
implicit val f1 = (y: Int) => y.toString
type L[X] = X => String
def foo[T : L](x: T):String = x
foo(121)
def bar[E, T : ({type L[X] = X => E})#L](x: T):E = x
//desugar => def goo2[E, T](x: T)(implicit ev: T => E):E = x
bar[String, Int](1231)
bar(1231)(x => s"** $x ** ") // remove [String, Int] because the types are explicitly provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment