[Haskell-cafe] Suspected stupid Haskell Question
gale at sefer.org
Wed Oct 17 07:38:42 EDT 2007
> When you can assume Ord, the standard solution
> is, as you suggest, something like...
Oops, sorry, doesn't typecheck. Here it is corrected:
> import qualified Data.Map as M
> import Data.List
> histogram = M.toList . foldl' (\m x -> M.insertWith' (+) x 1 m) M.empty
> This should work efficiently, with the right amount of laziness, even
> for very large lists.
Stuart's Arrows thing is much nicer when your list is small
enough to be held in memory all at once.
More information about the Haskell-Cafe