Skip to content

Instantly share code, notes, and snippets.

@nuttycom
Created July 25, 2011 15:17
Show Gist options
  • Save nuttycom/1104363 to your computer and use it in GitHub Desktop.
Save nuttycom/1104363 to your computer and use it in GitHub Desktop.
Pattern matching on path-dependent types
sealed trait A {
type X
case class B(x: X)
def b: B
}
case class J(x: String) extends A {
type X = String
override def b = B(x)
}
case class K(x: Int) extends A {
type X = Int
override def b = B(x)
}
object Main {
def main(argv: Array[String]) {
List(J("a"), K(1)).map(_.b).foreach {
case J#B(s) => println("String " + s)
case K#B(i) => println("Int " + i)
}
}
}
@nightwolfzor
Copy link

This doesnt work in Scala 2.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment