[Haskell-cafe] Suspected stupid Haskell Question

Stuart Cook scook0 at gmail.com
Wed Oct 17 07:19:27 EDT 2007


On 10/17/07, Peter Verswyvelen <bf3 at telenet.be> wrote:
> So in that case, the result should be a list of ordered pairs like:
> [("egg", 2), ("cheese", 1)]. Or a pair of two lists, like (["egg",
> "cheese"), (2,1)]. Otherwise you would not know which frequency belongs
> to which element?

> However, I suspect the experts here will be able to make that much
> shorter and more efficient (maybe using Data.Map?)


  import Control.Arrow
  import Data.List

  freqs = map (head &&& length) . group . sort

I have used this function quite a few times already.


Stuart


More information about the Haskell-Cafe mailing list