Created
July 25, 2011 15:17
-
-
Save nuttycom/1104363 to your computer and use it in GitHub Desktop.
Pattern matching on path-dependent types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesnt work in Scala 2.11