[clean-list] Can anyone improve this program?
Peter Achten
P.Achten at cs.ru.nl
Mon Jul 11 14:06:27 MEST 2005
Dear Jigang,
If you don't mind an additional class restriction on your function (viz.
Ord), then the following also works:
import StdEnv
Start = count [5,6,5,7,5,6]
count :: [a] -> [(a,Int)] | Ord, Eq a
count xs = map (\xs -> (hd xs,length xs)) (group (sort xs))
group :: [a] -> [[a]] | Eq a
group [] = []
group [x:xs] = [[x:eq_x]:group uneq_x]
where
(eq_x,uneq_x) = span ((==) x) xs
Regards,
Peter
At 01:33 AM 7/10/2005, you wrote:
>Hi Nick,
>
>Thank you for your email.
>
>What I want to do is to get the occurences of a element in a list, e.g.
>[5,6,5,7,5,6] => [(5,3),(6,2)(7,1)], without using a extra parameter like
>n in (count n list).
>
>I prefer
>Start = count [5,6,5,7,5,6]
>than
>
>Start = count n [5,6,5,7,5,6]
>
>How do you think about the next generation language, FP or OOP?
>
>Thank again.
>
>Jigang
>
>
>
>
>
>_______________________________________________
>clean-list mailing list
>clean-list at science.ru.nl
>http://mailman.science.ru.nl/mailman/listinfo/clean-list
More information about the clean-list
mailing list