[Haskell-cafe] Efficient functional idiom for histogram

Malcolm Wallace malcolm.wallace at cs.york.ac.uk
Fri Jul 31 16:54:23 EDT 2009


> In an imperative language like Python, I'd use a dictionary as an
> accumulator - something like
>
>    for el in input:
>        accums[i] = accums.get(i, 0) + 1

Haskell has efficient dictionary structures too, e.g. Data.Map

   List.foldl' (\m x-> Map.insertWith' (+) x 1 m) Map.empty

Regards,
     Malcolm



More information about the Haskell-Cafe mailing list