Proposal: Make intersect(By) lazier and faster
Bas van Dijk
v.dijk.bas at gmail.com
Thu Sep 16 12:20:17 EDT 2010
On Thu, Sep 16, 2010 at 6:16 PM, Duncan Coutts
<duncan.coutts at googlemail.com> wrote:
> 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.
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
More information about the Libraries
mailing list