KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to write a list comprehension to calculate the frequency of each distinct value in a list, but I'm having trouble with the last part. So far I have this: frequency :: Eq a => [a] -> [(Int,a)] frequency list = [(count y list,y) | y <- rmdups ] Something is wrong with the last part involving rmdups . The count function takes a character and then a list of characters and tells you how often that character occurs, the code is as follows: count :: Eq a => a -> [a] -> Int count x [] = 0 count x (y:ys) | x==y = 1+(count x ys) | otherwise = count x ys
Tags (comma-separated)
Save Edits
Cancel