[Haskell-cafe] Comments and/or Criticisms

rahn at ira.uka.de rahn at ira.uka.de
Mon Sep 10 03:12:18 EDT 2007


> countCS :: [Char] -> [(Char, Int)]

I use this

count :: (Ord a, Num b) => [a] -> (a -> b,[(a,b)])
count xs = ( flip (Map.findWithDefault 0) m , Map.assocs m )
     where m = Map.fromListWith (+) $ zip xs $ repeat 1

which returns the frequencies list as well as a query function that I  
found myself quite often useful.

/BR


More information about the Haskell-Cafe mailing list