Skip to content

Instantly share code, notes, and snippets.

@paulp
Created May 6, 2015 19:11
Show Gist options
  • Save paulp/6e95cbda72e845c63da6 to your computer and use it in GitHub Desktop.
Save paulp/6e95cbda72e845c63da6 to your computer and use it in GitHub Desktop.
classic scala
// Wherein scala assigns the constant type String("a") to a string "b".
// Idea by retronym in https://issues.scala-lang.org/browse/SI-7730
scala> def f[A <: AnyRef: scala.reflect.ClassTag](x: Any) = x match { case (a: A, x: (a.type forSome { type T })) => ((a, x)) }
warning: there was one feature warning; re-run with -feature for details
f: [A <: AnyRef](x: Any)(implicit evidence$1: scala.reflect.ClassTag[A])(A, A)
scala> final val x = "a"
x: String("a") = a
scala> f[x.type](x -> x)
res0: (String("a"), String("a")) = (a,a)
scala> f[x.type](x -> "b")
res1: (String("a"), String("a")) = (a,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment