Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created June 16, 2011 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kings13y/1028945 to your computer and use it in GitHub Desktop.
Save kings13y/1028945 to your computer and use it in GitHub Desktop.
Path Dependent types example
// 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