Skip to content

Instantly share code, notes, and snippets.

@larsrh
Created November 7, 2012 11:16
Show Gist options
  • Save larsrh/4030916 to your computer and use it in GitHub Desktop.
Save larsrh/4030916 to your computer and use it in GitHub Desktop.
Compiler failure in 2.10.x
sealed trait GenericList[+M[_]] {
final def :^:[A, N[X] >: M[X]](elem: N[A]): GenericCons[N, A, this.type] =
GenericCons[N, A, this.type](elem, this)
}
case class GenericCons[M[_], H, +T <: GenericList[M]](
head: M[H],
tail: T
) extends GenericList[M] {
}
case class GenericNil[M[_]]() extends GenericList[M] {
}
object TypelevelUsage extends App {
val klist = None :^: Option(3) :^: Some("foo") :^: GenericNil[Nothing]
// fails
klist match {
case GenericCons(optionInt1, GenericCons(optionInt2, GenericCons(someString, _))) =>
}
// fails, but with another message
/*klist match {
case GenericCons(optionInt1, GenericCons(optionInt2, _)) =>
}*/
// succeeds
klist match {
case GenericCons(optionInt1, _) =>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment