Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created February 7, 2014 20:53
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 kevinwright/8871644 to your computer and use it in GitHub Desktop.
Save kevinwright/8871644 to your computer and use it in GitHub Desktop.
trait Proletariat {
type BigNumberT
def retirementAge: BigNumberT
val bippy = "hi mum"
def twiddle = 42
def twaddle = 1
}
trait BiggerTwaddle {
def twaddle = 3
}
class Oppressor(@proxy val worker: Proletariat) extends BiggerTwaddle {
val twiddle = 69
}
//// expands to:
class Oppressor(val worker: Proletariat) extends BiggerTwaddle {
//This type delegate only works here because the delegated worker is a stable type
//possibly a Yorkshireman?
type BigNumberT = worker.BigNumberT
def retirementAge = worker.retirementAge
val bippy = worker.bippy
def twiddle = 69 //don't delegate, already defined
//twaddle already inhereted, so don't delegate
}
// Sample usage
val blueCollarWorker = new Proletariat {
type BigNumberT = Long
val retirementAge = 96L
}
val capitalism = new Oppressor(blueCollarWorker)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment