Scala programming problem