[swift-evolution] [Review] SE-0131: Add AnyHashable to the standard library
razielim at gmail.com
Tue Jul 26 00:17:57 CDT 2016
I’d only +1 this proposal if we can perform an implicit conversion. From SE-0116:
> The user model for this type would ideally align with our long-term goal of supporting Hashable existentials directly, so the type deserves some short-term compiler support to help us get there.
I read that as meaning that the interface should look as close as possible to what using a raw “Hashable” would look like, and that some short-term complier magic to achieve that would be acceptable. As far as that goes:
- unwrapping is functionally equivalent (upcasting from Any today, in the future from Hashable, but when upcasting all that matters is the destination type so NFC)
- wrapping is too verbose:
> /// let descriptions: [AnyHashable : Any] = [
> /// AnyHashable("😄"): "emoji",
> /// AnyHashable(42): "an Int",
> /// AnyHashable(Int8(43)): "an Int8",
> /// AnyHashable(Set(["a", "b"])): "a set of strings"
> /// ]
That would be a big regression in readability, IMO. Previously, you could declare those keys without the “AnyHashable” wrapper, and the bridging magic would turn Int -> NSNumber because that’s the way to make an Int conform to NSObject. It should be possible to teach the compiler how to turn a Hashable in to an AnyHashable implicitly.
But yeah, if we can do an implicit conversion, it’s a 👍 from me
> On 24 Jul 2016, at 00:26, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> Hello Swift community,
> The review of "SE-0131: Add AnyHashable to the standard library" begins now and runs through July 25. This proposal is a bit unusual, since it is a late additive proposal. The reason we need to do something here is as a critical part of "SE-0116: Import Objective-C id as Swift Any type”, enabling importing untyped NSDictionary's and NSSet’s properly. The core team considers this already conceptually approved for Swift 3 as part of SE-0116, but would greatly appreciate feedback on the details of the proposed design.
> The proposal is available here:
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> or, if you would like to keep your feedback private, directly to the review manager.
> What goes into a review?
> The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a change to Swift?
> * Does this proposal fit well with the feel and direction of Swift?
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> More information about the Swift evolution process is available at
> Thank you,
> -Chris Lattner
> Review Manager
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution