[darcs-users] darcs patch: Refactor add_to_list.

Thorkil Naur naur at post11.tele.dk
Sat Jan 17 15:52:11 UTC 2009


Hello,

On Saturday 17 January 2009 15:29, Eric Kow wrote:
> Refactor add_to_list.
> ---------------------
> > +-- | Add element @x@ to list @xs@ if it isn't there yet.
> >  add_to_list :: Eq a => a -> [a] -> [a]
> > hunk ./src/Darcs/Repository/Prefs.lhs 382
> > -add_to_list s [] = [s]
> > -add_to_list s (s':ss) = if s == s' then (s:ss) else s': add_to_list s ss
> > +add_to_list x xs = if x `elem` xs then xs else x : xs
> 
> Does it matter that x is now added to the front of the list instead of
> to the back?  (I guess we could do xs ++ [x] if it does indeed matter)

That would cause the list to be traversed twice.

> 
> -- 
> Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
> PGP Key ID: 08AC04F9
> 

Best regards
Thorkil


More information about the darcs-users mailing list