[darcs-users] darcs patch: Refactor add_to_list.
Petr Rockai
me at mornfall.net
Wed Jan 21 06:19:10 UTC 2009
Petr Rockai <me at mornfall.net> writes:
> Eric Kow <kowey at darcs.net> writes:
>> 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)
> The net effect of the ordering change is that when you pull from a completely
> new repository, it will be added as a first item to _darcs/prefs/repos instead
> of last. The function doesn't seem to be used for _darcs/prefs/sources, where
> ordering *does* matter (*but* current darcs gets it wrong anyway, so...).
PS: You can use Data.List.union when ordering doesn't matter:
add_to_list s l = l `union` [s]
(and you can probably replace add_to_list in its sole caller, since
this call is shorter than the even a call to add_to_list).
Yours,
Petr.
--
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentation
More information about the darcs-users
mailing list