[Haskell-cafe] Re: Deleting list of elements from Data.Set

apfelmus apfelmus at quantentunnel.de
Wed Jan 30 09:50:26 EST 2008


Gracjan Polak wrote:
>> Data.List.foldr (Data.Set.delete) s [1,3,5]
>> or
>> Data.List.foldl' (flip Data.Set.delete) s [1,3,5]
> 
> There will be a day when I finally grasp foldr/foldl :)

Maybe

   http://en.wikibooks.org/wiki/Haskell/Performance_Introduction
   http://www.haskell.org/haskellwiki/Stack_overflow

helps to make that day dawn earlier :)


Note that in your original approach of  fold (.) id  , it doesn't really 
matter whether you use  foldr  or  foldl'  (except for argument order!) 
because the latter would only evaluate to a function  Data.Set -> 
Data.Set  which is not very useful. In contrast, Duncan's code evaluates 
to  Data.Set  , that's what you want to be strict in.


Regards,
apfelmus




More information about the Haskell-Cafe mailing list