[darcs-users] [patch61] clean up elegant_merge (and 1 more)

Ganesh Sittampalam ganesh at earth.li
Wed Nov 18 14:26:29 UTC 2009


On Sat, 14 Nov 2009, Jason Dagit wrote:

> Sat Nov 14 14:31:05 PST 2009  Jason Dagit <dagit at codersbase.com>
>  * clean up elegant_merge

> -elegant_merge (p1 :\/: p2) =
> -  case commutex (p1 :< invert p2) of
> -  Just (ip2':<p1') -> case commutex (p1' :< p2) of
> -                      Nothing -> Nothing -- should be a redundant check
> -                      Just (_:<p1o) -> if unsafeCompare p1o p1
> -                                       then Just (invert ip2' :/\: p1')
> -                                       else Nothing
> -  Nothing -> Nothing
> +elegant_merge (p1 :\/: p2) = do
> +  ip2' :< p1' <- commutex (p1 :< invert p2)
> +  _ :< p1o <- commutex (p1' :< p2)
> +  if unsafeCompare p1o p1 -- should be a redundant check
> +    then return $ invert ip2' :/\: p1'
> +    else Nothing

You've moved the "should be a redundant check" comment from the second 
commutex call to the unsafeCompare. I guess that the comment really 
should cover both of these things, do you agree?

BTW the code could be further elegantised by using "guard".

If you agree about the comment, I suggest I accept this patch as it 
stands, particularly since other stuff depends on it, and one of us sends 
a follow-on to clarify the comment.

> Sat Nov 14 14:42:43 PST 2009  Jason Dagit <dagit at codersbase.com>
>  * replace commutex with commute in elegant_merge

Looks fine.

Ganesh


More information about the darcs-users mailing list