Skip to content
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

Implement Data.ByteString.Lazy.compareLength #300

Merged
merged 15 commits into from
Oct 16, 2020
Merged

Conversation

gutjuri
Copy link
Contributor

@gutjuri gutjuri commented Oct 8, 2020

related to #298

I tested the function in GHCi.
Unfortunately I do not yet understand how to add tests to the testsuite.
I'd be great if someone could give me a point in the right direction on where to add tests.

Concerning the documentation: I described the compareLength as being O(n) (where n is the length of the ByteString). This is a bit imprecise, because it neglects the Int parameter entirely. However, I was not sure on how to refer to this parameter in the documentation.

Copy link
Contributor

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!
Tests go into tests/Properties.hs

Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
@Bodigrim
Copy link
Contributor

Bodigrim commented Oct 10, 2020

Almost there!
Please add one more test \xs l -> compareLength xs l == compare (length xs) l.

We can also benefit from rewrite rules, similar to text: http://hackage.haskell.org/package/text-1.2.4.0/docs/src/Data.Text.html#compareLength

Do not forget to re-export this function from Data.ByteString.Lazy.Char8 as well.

Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
@gutjuri gutjuri marked this pull request as ready for review October 10, 2020 19:19
@gutjuri gutjuri changed the title WIP: Implement Data.ByteString.Lazy.compareLength Implement Data.ByteString.Lazy.compareLength Oct 10, 2020
@Bodigrim Bodigrim linked an issue Oct 10, 2020 that may be closed by this pull request
@Bodigrim Bodigrim requested a review from sjakobi October 12, 2020 18:40
Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
Data/ByteString/Lazy.hs Outdated Show resolved Hide resolved
Copy link
Member

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Bodigrim Bodigrim merged commit bd5412c into haskell:master Oct 16, 2020
@Bodigrim
Copy link
Contributor

@gutjuri merged, thanks!

@Bodigrim Bodigrim added this to the 0.11.1.0 milestone Oct 16, 2020
Comment on lines +1427 to +1432
-- Required for rewrite rules for 'compareLength'
negateOrdering :: Ordering -> Ordering
negateOrdering LT = GT
negateOrdering EQ = EQ
negateOrdering GT = LT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks redundant to me, it is just compare EQ.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I open a miniature pull request to delete negateOrdering and replace its call site with compare EQ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, much appreciated. Could you please also combine all rules for compareLength under a single RULES pragma?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement compareLength for lazy bytestrings
4 participants