Functional and Imperative way of adding all elements of a list