Implement sum as a function