
===== Original Message From "xoo"
===== 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 ]

Probably is a homework question, so HINT: you can do it using 2 and only 2 prelude functions and no additional function definitions of your own. -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Wed, 5 Jun 2002, Andy Fugard wrote:
===== Original Message From "xoo"
===== 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 ]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello! On Wed, Jun 05, 2002 at 07:04:28PM +0100, Andy Fugard wrote:
===== Original Message From "xoo"
===== 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!
Yep. And not call the parameter for the single 'a' "xs". That's misleading.
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 ...
[...]
Why not combine filter and length appropriately? Kind regards, Hannah.
participants (3)
-
Andy Fugard
-
Hal Daume III
-
Hannah Schroeter