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