Generating smooth numbers in Haskell
smooth limit = foldlM (`repeatMul` limit) 1


Intermediate steps:

smooth limit = (`inner` 1)
    where inner [] = pure
          inner (x:xs) = flip (`repeatMul` limit) x &gt;=&gt; inner xs

smooth limit = (`inner` 1)
    where inner = foldr (&gt;=&gt;) pure . map (flip (`repeatMul` limit))

smooth limit xs = (foldr (&gt;=&gt;) pure $ map (flip (`repeatMul` limit)) xs) 1

smooth limit = foldl (&gt;&gt;=) (pure 1) . map (flip (`repeatMul` limit))

smooth limit = foldlM (flip id) 1 . map (flip (`repeatMul` limit)) -- did I mention foldlM has its argument order as stupid as repeatMul? :P




Extra answer:

There is no need for the no-duplicates bookkeeping of sets - every natural has a unique prime factorization. Anyway, here as a fold from the right, if repeatMul produced a set:

smooth limit = foldr (foldMap . repeatMul limit) (singleton 1)


Note that this also works for the list case with [1] in place of singleton 1.