[darcs-users] darcs patch: Refactor add_to_list.

Trent W. Buck trentbuck at gmail.com
Sun Jan 18 01:34:16 UTC 2009


On Sat, Jan 17, 2009 at 08:28:01PM -0500, Max Battcher wrote:
> Trent W. Buck wrote:
> > 
> > On Sat, Jan 17, 2009 at 02:29:57PM +0000, 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)
> > 
> > I don't know.  It passes the functional tests...
> > 
> > add_to_list is only used once, so I'll study the caller and try to see
> > if the order matters.
> 
> As revised, it certainly appears that add_to_list is really add_to_set...
> Is there an existing library call that might be better used? 

I had a quick look and couldn't see one.

I assume it's (mis)named add_to_list because that's what Emacs Lisp
calls it.  Maybe consOntoSet would be better? ;-P


More information about the darcs-users mailing list