Skip to content

Instantly share code, notes, and snippets.

@erangaeb
Last active January 31, 2016 13:39
Show Gist options
  • Save erangaeb/c4f40ed9732b635cf845 to your computer and use it in GitHub Desktop.
Save erangaeb/c4f40ed9732b635cf845 to your computer and use it in GitHub Desktop.
Alternative to Inheritance via self typed annotation
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