Counting occurrences question

Andy Fugard andyfugard@ecosse.net
Wed, 5 Jun 2002 19:04:28 +0100


>===== Original Message From "xoo" <ixoo21@hotmail.com> =====
>hi.. i was just wondering if some body could give a simple equation for the 
following situation.other than recursion plz..
>
>occurrences :: Eq a => a -> [a] -> [a]
>--occurrences xs ys returns the number of times that xs  occurs in ys


You may find it easier if you make

  occurrences :: Eq a => a -> [a] -> Integer

since it would seem it is to return a number, and not another list!

Also I would guess the function will have a form something like

  occurrences x xs = foldr (countOp x) 0 xs
      where countOp :: Eq a => a -> a -> Integer -> Integer
            ...

I'm not sure if I should go any further, in case this is a homework 
question...

Andy

--
[ Andy Fugard ]
[ +44 (0)7901 603075 ]