Proposal: Make intersect(By) lazier and faster

Duncan Coutts duncan.coutts at googlemail.com
Thu Sep 16 12:16:44 EDT 2010


On 16 September 2010 17:10, Bas van Dijk <v.dijk.bas at gmail.com> 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.

Duncan


More information about the Libraries mailing list