Im trying to convert a string to it's unique chars along with an integer counter to the following interface:
empty :: Table k vinsert :: Eq k => Table k v -> k -> v -> Table k vexists :: Eq k => Table k v -> k -> Boollookup :: Eq k => Table k v -> k -> Maybe vdelete :: Eq k => Table k v -> k -> Table k viterate :: Table k v -> (b -> (k, v) -> b) -> b -> bkeys :: Table k v -> (b -> k -> b) -> b -> bvalues :: Table k v -> (b -> v -> b) -> b -> b
My function so far is as follows:
auxCharacterCounts :: String -> Table Char IntauxCharacterCounts (x:xs)| length (x:xs) > 1 = (Table.insert Table.empty x (length $ filter (\y -> y == x) (x:xs)))
For example passing the string "sassa" to auxCharacterCounts
and then running a lookup tablename 's'
would yield Just 3
Giving us the indication that we have 3 occurences of the char 's' in the string "sassa". What im stuck at is wrapping my head on how to get the other characters, so to speak running lookup tablename 'a'
would yield the result Just 2
(against the string "sassa")
Im not sure how to run this recursivly, can I pass the tail somehow? But if I did it will find the char 's' several times more and might result in unnessecary resource usage?
Cheers.