Skip to content

Instantly share code, notes, and snippets.

@mielientiev
Last active January 22, 2017 19:23
Show Gist options
  • Save mielientiev/1873b2aea8f6f2bff81e13b597a7849c to your computer and use it in GitHub Desktop.
Save mielientiev/1873b2aea8f6f2bff81e13b597a7849c to your computer and use it in GitHub Desktop.
trait TestCo {
type CoVariant[+T, _ <: Exception]
def unwrap[T](value: => CoVariant[T, _ <: Exception]): T
}
// works fine, since Option is covariant
class TestCoImpl extends TestCo {
type CoVariant[+T, _ <: Exception] = Option[T]
def unwrap[T](value: => CoVariant[T, _ <: Exception]): T = value.get
}
//covariant type CoVariant occurs in contravariant position in type => TestCoFailed.this.CoVariant[T] of value value
// def unwrap[T](value: => CoVariant[T]): T = value
class TestCoFailed extends TestCo {
type CoVariant[+T, _ <: Exception] = T
def unwrap[T](value: => CoVariant[T, _ <: Exception]): T = value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment