Proposal: Make intersect(By) lazier and faster

Daniel Fischer daniel.is.fischer at web.de
Thu Sep 16 13:26:53 EDT 2010


On Thursday 16 September 2010 18:20:17, Bas van Dijk wrote:
> 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

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.



More information about the Libraries mailing list