Example code (and more) from Odersky's "Programming in Scala", second edition.