Skip to content

Add specializations for all functions from Generic - #322

Merged
Shimuuar merged 6 commits into
haskell:masterfrom
Shimuuar:missing-exports
Jul 12, 2020
Merged

Shimuuar merged 6 commits into
haskell:masterfrom
Shimuuar:missing-exports

Conversation

@Shimuuar

Copy link
Copy Markdown
Contributor

Progress is tracked in #299

@Shimuuar Shimuuar changed the title WIP: add specializations for all functions from Generic Add specializations for all functions from Generic Jun 27, 2020
@Shimuuar
Shimuuar requested review from Bodigrim and lehins June 27, 2020 19:44
@Shimuuar

Copy link
Copy Markdown
Contributor Author

Now all differences between Generic and rest of immutable vectors are accounted for. There're still mutable vectors. But that's much bigger fish to fry.

@lehins lehins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't feel like this is 100% correct wording for cmpBy functions:

Check if two vectors are equal using supplied comparison function

Since it's the ordering it will produce, not just equality.

But I can't think of a way to rephrase it in order to make it better. And it is definitely better than it was before, so 👍 from me.

@Shimuuar

Copy link
Copy Markdown
Contributor Author

I don't feel like this is 100% correct wording for cmpBy functions:

Ah! That's case of "I copy-paste, therefore I don't think". Equality is remnant of eqBy haddock

Comment thread Data/Vector.hs Outdated
{-# INLINE eqBy #-}
eqBy = G.eqBy

-- | /O(n)/ Check if two vectors are equal using supplied comparison function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's important to mention here and above what happens for vectors of different length.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I finally updated haddocks for cmpBy

Comment thread Data/Vector.hs Outdated
-- vector elements. Comparison works same as for lists.
--
-- > cmpBy compare == compare
cmpBy :: (a -> a -> Ordering) -> Vector a -> Vector a -> Ordering

@Bodigrim Bodigrim Jul 9, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be cmpBy :: (a -> b -> Ordering) -> Vector a -> Vector b -> Ordering?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch. That is the type of G.cmpBy, so it seems like it should apply to specialized versions as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I specialized these to a -> a -> Ordering because almost always vectors of the same type are compared and if someone needs most generic case there's Data.Vector.Generic.cmpBy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not see a good reason to restrict specialized versions in such way. This is both less powerful and less expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought that a -> b -> Ordering is somewhat unexpected. Anyway I changed specializations to a -> b -> Ordering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please do the same for eqBy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for noticing things.

@Shimuuar
Shimuuar merged commit 56e20cc into haskell:master Jul 12, 2020
@Shimuuar
Shimuuar deleted the missing-exports branch July 12, 2020 17:43
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.

3 participants