Skip to content

Instantly share code, notes, and snippets.

@dabd
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save dabd/c59477e4dfb3e0193305 to your computer and use it in GitHub Desktop.

Select an option

Save dabd/c59477e4dfb3e0193305 to your computer and use it in GitHub Desktop.
frequencies :: [Integer] -> [(Integer, Int)]
frequencies xs = map (\x -> (head x, length x)) . group . sort $ xs
@folsen
Copy link

folsen commented Jun 30, 2014

frequencies :: [Integer] -> [(Integer, Int)]
frequencies xs = map f . group . sort $ xs
  where
    f [] = error "This will always be an uncaught exception, but can't happen because group always returns a non-empty list to map over"
    f xs = (head xs, length xs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment