Coursera's Programming Languages course homework in Scala