Hahahaha have rmdups on pg. 86 of Programming at Haskell by Graham Hutton. It is perfect and recursive. It is also convenient in many situations.
Here is my single line rmdups which gives the same results as nub or Hutton's.
rmdups ls = [d|(z,d)<- zip [0..] ls,notElem d $ take z ls]
It can be used to count individual elements of the list.
dl = "minimum-maximum" [ (d,sum [1|x<-dl,d == x]) | d<-rmdups dl]
[('T', 6), ('I', 3), ('N', 1), ('and', 2), ('-', 1), ('a', 1), ( 'x', 1)]
fp_mora
source share