Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
Last active March 28, 2017 00:22
Show Gist options
  • Select an option

  • Save sir-wabbit/56028633ef73faeec0f5d3e7e3a14746 to your computer and use it in GitHub Desktop.

Select an option

Save sir-wabbit/56028633ef73faeec0f5d3e7e3a14746 to your computer and use it in GitHub Desktop.
def coerce[U, V](u: U): V = {
trait F { type R }
trait X extends F { type R = U }
trait Y extends F { type R = V }
final case class T[A <: F](value: A#R)
val a: T[X with Y] = new T[Y with X](u)
a.value
}
println(coerce[String, Int]("hello"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment