sum, product, length implemented using foldLeft