Skip to content

FloatingPoint should imply Hashable. #7870

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

Merged
merged 1 commit into from
Mar 5, 2017
Merged

FloatingPoint should imply Hashable. #7870

merged 1 commit into from
Mar 5, 2017

Conversation

stephentyrone
Copy link
Contributor

This is a bug fix adding conformance to Hashable to the FloatingPoint protocol. The concrete types already conform.

Resolves SR-4132.

@stephentyrone
Copy link
Contributor Author

@swift-ci Please smoke test.

@stephentyrone stephentyrone requested a review from dabrahams March 2, 2017 15:23
@jrose-apple
Copy link
Contributor

I'm not sure why FloatingPoint would imply Hashable. The two concepts (in the technical sense) have nothing to do with each other.

@dabrahams
Copy link
Contributor

dabrahams commented Mar 3, 2017 via email

@jrose-apple
Copy link
Contributor

That's still not true. You can implement Collection on any BinaryInteger type to give you a collection of Bools, but it doesn't mean they're related concepts.

@stephentyrone
Copy link
Contributor Author

stephentyrone commented Mar 3, 2017

@jrose-apple That's a fair point, and with conditional conformance we probably don't need this. Without conditional conformance, it's something of a minor pain, forcing you to define your own FloatingPoint + Hashable protocol. =)

@dabrahams
Copy link
Contributor

@jrose-apple @stephentyrone Hashable conformance confers a core capability that every type should provide if it can, just like Equatable and Comparable. There's almost no excuse for any Equatable thing not to also be Hashable; the exception is when the underlying representation may be denormalized in some way that makes them impossible or expensive to normalize (e.g. Set). Floating point numbers have denormalized forms, so for me this comes down to the cost of normalization. If @stephentyrone can't imagine a representation whose normalization is much more expensive than the subsequent hashing step, I think the conformance belongs.

@jrose-apple
Copy link
Contributor

That's new information that I'm not sure is well-established. I'd say Hashable is even more "core" than Comparable, but that still doesn't mean it has anything to do with FloatingPoint. It's not like it's hard or less correct to make it an additional constraint on your generic functions.

(I'm not even against providing a default implementation. It just bothers me to see unrelated protocols connected together because it's convenient.)

@dabrahams
Copy link
Contributor

I don't buy the premise that they're unrelated. Hashable is related to Equatable, and FloatingPoint is Equatable, presumably with enough additional constraints that Hashable conformance is practical. Concept clustering is a thing, and separating concepts should require evidence.

BTW, Hashable is exactly as core as Comparable. In fact I think it can be implemented in all the same cases. Maybe they should be folded together.

@stephentyrone
Copy link
Contributor Author

Hashable is related to Equatable, and FloatingPoint is Equatable, presumably with enough additional constraints that Hashable conformance is practical.

If this is the standard, then yes it should conform to Hashable, and it is a bug for it not to.

@dabrahams dabrahams merged commit 7af65d9 into swiftlang:master Mar 5, 2017
@stephentyrone stephentyrone deleted the FloatingPoint-Hashable branch April 17, 2017 17:33
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