Created
October 28, 2015 20:17
-
-
Save dasch/fed7db5b90ed08b8b2cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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