Last active
January 31, 2016 13:39
-
-
Save erangaeb/c4f40ed9732b635cf845 to your computer and use it in GitHub Desktop.
Alternative to Inheritance via self typed annotation
This file contains hidden or 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
trait Lambda { | |
val l = "Lambda" | |
} | |
trait Calculus { | |
this: Lambda => | |
val c = "Calculus" | |
val lc = l + c | |
} | |
trait Turing { | |
this: Calculus => | |
val t = "Turing" | |
val lct = l + c + t // compilation error(cannot access l) | |
} | |
// usage | |
val universe = new Turing with Calculus with Lambda | |
println(universe.c) | |
println(universe.lc) | |
println(universe.t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment