Skip to content

Instantly share code, notes, and snippets.

@dasch
Created October 28, 2015 20:17
Show Gist options
  • Save dasch/fed7db5b90ed08b8b2cd to your computer and use it in GitHub Desktop.
Save dasch/fed7db5b90ed08b8b2cd to your computer and use it in GitHub Desktop.
counts : List comparable -> List (comparable, Int)
counts items =
let
counts' items =
case items of
[] -> []
(x, nx) :: [] -> [(x, nx)]
(x, nx) :: (y, ny) :: rest ->
if x == y then counts' ((x, nx + ny) :: rest)
else (x, nx) :: counts' ((y, ny) :: rest)
in
List.sort items
|> List.map (\x -> (x, 1))
|> counts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment