[Haskell-cafe] Comments and/or Criticisms

PR Stanley prstanley at ntlworld.com
Sun Sep 9 21:58:57 EDT 2007


Hi
Any comments and/or criticisms would be most appreciated:
--count the occurrences of char in string
countC :: Char -> [Char] -> Int
countC x xs = sum [1 | c <- xs, c == x]

--count occurrences of chars in string
countCS :: [Char] -> [(Char, Int)]
countCS xs = [(x, (countC x xs)) | x <- [' '..'z'], (countC x xs) > 0]

Can anyone come up with a better alternative?
Thanks, Paul



More information about the Haskell-Cafe mailing list