-
Notifications
You must be signed in to change notification settings - Fork 32
add equal function #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This looks good, but I wonder if we should add this now, or try to figure out how to add this to Prelude as an |
|
I could move this over to a Prelude PR once things are in place there |
src/Data/Record.purs
Outdated
| , RowCons name ty tailRow row | ||
| , EqualFields tail row | ||
| ) => EqualFields (Cons name ty tail) row where | ||
| equalFields _ a b = get' a == get' b && rest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @justinwoo! I think it might be more efficient to use an if expression to make this short-circuit:
equalFields _ a b =
if get' a == get' b
then equalRest a b -- evaluate this fully only inside the true branch
else false
where
get' = get (SProxy :: SProxy name)
equalRest = equalFields (RLProxy :: RLProxy tail)(I think the strictness means that the rest of the record would be compared before being passed to &&)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get' a == get' b && equalRest a b would also short circuit :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay! Sometimes I forget we have compiler magic – thanks! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated! thanks
|
@justinwoo Could you please rebase this? |
|
rebased! |
|
Thanks! |
I realized that I need this function but we don't seem to have it yet