Haskell 98 Report

Tom Pledger Tom.Pledger@peace.com
Thu, 31 May 2001 08:16:44 +1200


Zhanyong Wan writes:
 :
 | I can't help wondering why it isn't
 | 
 |   deleteBy'          :: (a -> Bool) -> [a] -> [a]
 |   deleteBy' f []     = []
 |   deleteBy' f (y:ys) = if f y then ys else
 |                          y : deleteBy' f ys

     deleteBy'' f = filter (not . f)


Malcolm Wallace writes:
 :
 | >      intersectBy :: (a -> b -> Bool) -> [a] -> [b] -> [a]
 | 
 | Although curiously, its dual 'unionBy' cannot also take the more
 | general type
 | 
 |         unionBy :: (a -> b -> Bool) -> [a] -> [b] -> [a]
 | 
 | at least, not with its current specification in terms of 'nubBy'.

That suggests a reason to leave the type of intersectBy alone - the
generalisation would arbitrarily favour the first list's type over the
second list's type.  To me, the word "intersect" implies symmetry.

- Tom