charsCount String Char Int charsCount charsCount str charsCount str wh

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