Skip to content

Instantly share code, notes, and snippets.

@davidpeklak
Last active August 29, 2015 13:57
Show Gist options
  • Save davidpeklak/9421853 to your computer and use it in GitHub Desktop.
Save davidpeklak/9421853 to your computer and use it in GitHub Desktop.
OrType
object Type {
class |:|[A, B]
implicit def orTypeA[A, B](implicit a: A): |:|[A, B] = new |:|[A, B]
implicit def orTypeB[A, B](implicit b: B): |:|[A, B] = new |:|[A, B]
type \:/[T, U] = {type λ[X] = (X <:< T) |:| (X <:< U)}
object Test {
case class One(x: Int)
case class Two(x: Int)
case class Three(x: Int)
case class Wrap[A: (One \:/ Two)#λ](a: A)
val w1 = Wrap(One(1))
val w2 = Wrap(Two(2))
// does not compile
val w3 = Wrap(Three(3))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment