Code from Types And Programming Languages - in Scala