= Solution
For exact ordered numbers, first discard multipliers equal to one and reject those below one:
``
hamming' :: (Ord a, Num a) => [a] -> [a]
hamming' as
| any (<1) as = error "multipliers below one violate the ordered contract"
| otherwise = hs
where
bs = filter (>1) as
hs = 1 : case bs of
[] -> []
_ -> foldr1 merge [map (a*) hs | a <- bs]
``
The <type signature> has exactly the numeric and ordering constraints used by the definition. For a finite nonempty collection of multipliers greater than one, this is the same <sorted multiplicative closure stream> construction as before, merging one scaled copy per multiplier. It is infinite and strictly increasing; local finiteness below any bound and the smaller-predecessor argument prove completeness and <productivity>. In particular, `[2,3,5]` reproduces `hamming`.
\b[The literal contract for arbitrary positive multipliers is impossible.] A multiplier strictly between zero and one would require a value smaller than the initial one; an empty list or the list `[1]` generates only one value. The definition returns the finite closure `[1]` in those degenerate cases. A multiplier equal to one adds no mathematical values and would introduce an unnecessary circular merge demand if left in the feedback streams. The order and growth proof assumes exact arithmetic with the usual laws; the broad numeric type alone cannot prevent floating-point rounding or bounded overflow.
Back to article page