charsCount String Char Int charsCount charsCount str addToSet str wher

1
2
3
4
5
6
7
charsCount :: String -> [(Char, Int)]
charsCount [] = []
charsCount str = addToSet str []
where addToSet [] set = set
addToSet (x:xs) [] = addToSet xs ((x, 1):[])
addToSet (x:xs) ((char, cnt):lastSet) | x == char = addToSet xs ((char, cnt+1):lastSet)
addToSet (x:xs) ((char, cnt):lastSet) | otherwise = (char, cnt) : addToSet (x:xs) lastSet