darcs

Patch 61 clean up elegant_merge (and 1 more)

Title clean up elegant_merge (and 1 more)
Superseder Nosy List dagit, darcs-users, ganesh
Related Issues
Status accepted Assigned To ganesh
Milestone

Created on 2009-11-14.22:46:43 by dagit, last changed 2009-11-22.16:24:52 by ganesh.

Files
File name Status Uploaded Type Edit Remove
clean-up-elegant_merge.dpatch dagit, 2009-11-14.22:46:42 text/x-darcs-patch
unnamed dagit, 2009-11-14.22:46:42 text/plain
unnamed dagit, 2009-11-19.02:45:38 text/html
See mailing list archives for discussion on individual patches.
Messages
msg9278 (view) Author: dagit Date: 2009-11-14.22:46:42
Trying to help elegant_merge live up to its name.

Should be good to go.  Witnesses and tests passed locally.

Thanks,
Jason

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

Sat Nov 14 14:42:43 PST 2009  Jason Dagit <dagit@codersbase.com>
  * replace commutex with commute in elegant_merge
Attachments
msg9410 (view) Author: ganesh Date: 2009-11-18.14:27:14
On Sat, 14 Nov 2009, Jason Dagit wrote:

> Sat Nov 14 14:31:05 PST 2009  Jason Dagit <dagit@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@codersbase.com>
>  * replace commutex with commute in elegant_merge

Looks fine.

Ganesh
msg9423 (view) Author: dagit Date: 2009-11-19.02:45:38
On Wed, Nov 18, 2009 at 6:26 AM, Ganesh Sittampalam <ganesh@earth.li> wrote:

> On Sat, 14 Nov 2009, Jason Dagit wrote:
>
>  Sat Nov 14 14:31:05 PST 2009  Jason Dagit <dagit@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?
>

When I read the code, what looked redundant to me was the check that p1o and
p1 are the same.  On the other hand, the comment seems odd and I was very
tempted to remove it.  It could refer to propagating the Nothing value as
well.  Is it possible we should remove the second commutex and the unsafe
compare because they are redundant checks (paranoid checks?)?


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

Oh, I hadn't thought of that.  I'll try to figure out how that should work
in a follow up patch if we decide to keep the unsafeCompare...

>
> 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.


I agree we should do something as a follow up.  Would it be okay if we
removed the second commutex and the unsafeCompare?

Jason
Attachments
msg9427 (view) Author: ganesh Date: 2009-11-19.20:59:55
On Wed, 18 Nov 2009, Jason Dagit wrote:

> I agree we should do something as a follow up.  Would it be okay if we
> removed the second commutex and the unsafeCompare?

I think that's reasonable.

Ganesh
msg9458 (view) Author: ganesh Date: 2009-11-22.16:24:52
This was applied a while ago but darcswatch didn't notice
History
Date User Action Args
2009-11-14 22:46:43dagitcreate
2009-11-18 14:21:04ganeshsetassignedto: ganesh
nosy: + ganesh
2009-11-18 14:26:36ganeshsetstatus: needs-review -> review-in-progress
2009-11-18 14:27:14ganeshsetmessages: + msg9410
2009-11-19 02:45:39dagitsetfiles: + unnamed
messages: + msg9423
2009-11-19 20:59:55ganeshsetmessages: + msg9427
2009-11-19 21:00:54ganeshsetstatus: review-in-progress -> accepted-pending-tests
2009-11-22 16:24:52ganeshsetstatus: accepted-pending-tests -> accepted
messages: + msg9458