So I already have a function that finds the number of occurrences in a list using maps.
occur :: [a] -> Map a a
occur xs = fromListWith (+) [(x, 1) | x <- xs]
For example if a list [1,1,2,3,3]
is inputted, the code will output [(1,2),(2,1),(3,2)]
, and for a list [1,2,1,1]
the output would be [(1,3),(2,1)]
.
I was wondering if there's any way I can change this function to use foldr instead to eliminate the use of maps.