Lists form a monoid structure with an associative binary operation ++ and a neutral element [] . That is, we have
[] ++ xs = xs = xs ++ [] (xs ++ ys) ++ zs = xs ++ (ys ++ zs)
Meanwhile, the numbers have a lot of monoid structure, but it is important here that where the operation is * , and the neutral element is 1 .
1 * x = x = x * 1 (x * y) * z = x * (y * z)
The product function is not only a map from lists of numbers to numbers: it is a monoid homomorphism that reflects the monoid structure of the list in a numerical monoid. Cardinally
product (xs ++ ys) = product xs * product ys
and
product [] = 1
In fact, in order to get the first, we are largely forced to impose ourselves on the latter.
source share