What I wouldn't give for a good sum type. This would be really easy - and clear - in Scala.