fork(14) download
  1. import Data.List
  2.  
  3. add :: Eq a => a -> [(a, Int)] -> [(a, Int)]
  4. add x [] = [(x, 1)]
  5. add x ((y, n):rest) = if x == y
  6. then (y, n+1) : rest
  7. else (y, n) : add x rest
  8.  
  9. count :: Eq a => [a] -> [(a, Int)]
  10. count = sortBy f . foldr add [] where
  11. f (_, x) (_, y) = compare y x
  12.  
  13. main = print $ count "Hello"
Success #stdin #stdout 0s 6280KB
stdin
Standard input is empty
stdout
[('l',2),('o',1),('e',1),('H',1)]