A simple exercise in functional programming