Created
June 16, 2011 09:28
-
-
Save kings13y/1028945 to your computer and use it in GitHub Desktop.
Path Dependent types example
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
// First a simple example of Tuple creation | |
val myTuple2 = ("A", 1) | |
val myTuple3 = ("B", 2, true) // creates a Tuple3 of String, Int, Boolean | |
// Not on to the path dep types stuff | |
trait BaseTrait { | |
type T | |
val baseA : T | |
} | |
class ChildA[String](param : String) extends BaseTrait { | |
type T = String | |
override val baseA = param | |
println(baseA) | |
} | |
val childA = new ChildA("A") | |
type B = String | |
class ChildB[String](param : String) extends BaseTrait { | |
// type T = B // Won't compile - baseA (below) has an incompatible type ! | |
// type T = childA.T // Won't compile - baseA (below) has an incompatible type ! | |
type T = String | |
override val baseA = param | |
println(baseA) | |
} | |
val childB = new ChildB("B") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment