
On Thursday 16 September 2010 18:20:17, Bas van Dijk wrote:
On Thu, Sep 16, 2010 at 6:16 PM, Duncan Coutts
wrote: On 16 September 2010 17:10, Bas van Dijk
wrote: However I like using a 'filter' more than using a list comprehension:
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] intersectBy _ [] _ = [] intersectBy _ _ [] = [] intersectBy eq xs ys = filter (\x -> any (eq x) ys) xs
Hopefully this definition can even benefit from foldr/build fusion using the filter RULES in GHC.List:
It should not make any difference. List comprehensions can also be fused using foldr/build fusion because the list combrehension is desugared into uses of foldr and build. It is also unlikely to fuse anyway because the compiler would need to know at the call site that the two lists are non-empty.
Agreed, but my reason for proposing using 'filter' instead of using a list comprehension is that I find it more "denotational". However, I think that's a matter of taste.
Bas
I don't care either way, I just inserted two equations to deal with empty lists before the current implementation. If a preference for using filter, the list comprehension or anything else emerges, that'll be fine with me.