17 Oct
2007
17 Oct
'07
5:08 p.m.
I wrote:
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. -Yitz