Use the functions, remdup
, elemOcc
, and map
to define a function, occurrences, that receives a list of characters and returns a list of pairs of an element and the number of its occurrences in the input list. For example:
occurrences [‘a’, ‘c’, ‘d’, ‘a’, ‘c’] = [(‘a’, 2), (‘c’, 2), (‘d’, 1)]
occurrences :: [Char] -> [(Char,Int)]
occurrences xs = zip (??) (??)
remdup :: [Char]->[Char]
remdup [] = []
remdup (x:xs) = x : remdup (…)
elemOcc :: Char-> [Char]->Int
elemOcc x = length . (filter ??)