[Discussion] Can we make `.Type` Hashable?


(Adrian Zubarev) #1

Additive question:

Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

路路路

--
Adrian Zubarev
Sent with Airmail


(David Sweeris) #2

+1

路路路

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Sean Heber) #3

+1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:

l8r
Sean

路路路

On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:

+1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.

On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
+1

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

聽聽鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Matthew Johnson) #4

+1 here as well. It would be nice to have.

路路路

On Jul 1, 2016, at 9:15 AM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:

+1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:

l8r
Sean

On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:

+1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.

On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
+1

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

聽聽鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Keith Smiley) #5

This would be great. I've solved this recently by making a TypeRepresentation
type that is initialized with any T, and conforms to Hashable. Of course
internally this just uses String(T), but at least that's abstracted from the
caller.

路路路

--
Keith Smiley

On 07/01, Matthew Johnson via swift-evolution wrote:

+1 here as well. It would be nice to have.

> On Jul 1, 2016, at 9:15 AM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:
>
> +1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:
>
> l8r
> Sean
>
>
>> On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:
>>
>> +1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.
>>
>> On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
>> +1
>>
>>> On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:
>>>
>>> Additive question:
>>>
>>> 鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
>>> I really would want to use these in dictionaries or sets :slight_smile:
>>>
>>> [Any.Type: ValueType]
>>>
>>> Set<Any.Type> // Union type universe
>>>
>>>
>>>
>>>
>>> --
>>> Adrian Zubarev
>>> Sent with Airmail
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Alex Migicovsky) #6

Hi Keith,

As a small aside, I鈥檇 suggest using ObjectIdentifier instead of a String to back your TypeRepresentation struct. ObjectIdentifier is Hashable and it has an initializer that accepts any type. The benefit of your TypeRepresentation type over ObjectIdentifier is that you can restrict the TypeRepresentation struct to only accept type parameters in its initializer (so you know you鈥檙e storing a type and not an object). ObjectIdentifier accepts both objects and types.

- Alex

路路路

On Jul 1, 2016, at 10:57 AM, Keith Smiley via swift-evolution <swift-evolution@swift.org> wrote:

This would be great. I've solved this recently by making a TypeRepresentation
type that is initialized with any T, and conforms to Hashable. Of course
internally this just uses String(T), but at least that's abstracted from the
caller.

--
Keith Smiley

On 07/01, Matthew Johnson via swift-evolution wrote:

+1 here as well. It would be nice to have.

On Jul 1, 2016, at 9:15 AM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:

+1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:

l8r
Sean

On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:

+1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.

On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
+1

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

聽聽鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Keith Smiley) #7

Oh awesome! We'll definitely switch to that. Thanks!

路路路

--
Keith Smiley

On 07/01, Alex Migicovsky wrote:

Hi Keith,

As a small aside, I鈥檇 suggest using ObjectIdentifier instead of a String to back your TypeRepresentation struct. ObjectIdentifier is Hashable and it has an initializer that accepts any type. The benefit of your TypeRepresentation type over ObjectIdentifier is that you can restrict the TypeRepresentation struct to only accept type parameters in its initializer (so you know you鈥檙e storing a type and not an object). ObjectIdentifier accepts both objects and types.

- Alex

> On Jul 1, 2016, at 10:57 AM, Keith Smiley via swift-evolution <swift-evolution@swift.org> wrote:
>
> This would be great. I've solved this recently by making a TypeRepresentation
> type that is initialized with any T, and conforms to Hashable. Of course
> internally this just uses String(T), but at least that's abstracted from the
> caller.
>
> --
> Keith Smiley
>
> On 07/01, Matthew Johnson via swift-evolution wrote:
>> +1 here as well. It would be nice to have.
>>
>>
>>> On Jul 1, 2016, at 9:15 AM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:
>>>
>>> +1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:
>>>
>>> l8r
>>> Sean
>>>
>>>
>>>> On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:
>>>>
>>>> +1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.
>>>>
>>>> On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
>>>> +1
>>>>
>>>>> On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:
>>>>>
>>>>> Additive question:
>>>>>
>>>>> 鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
>>>>> I really would want to use these in dictionaries or sets :slight_smile:
>>>>>
>>>>> [Any.Type: ValueType]
>>>>>
>>>>> Set<Any.Type> // Union type universe
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Adrian Zubarev
>>>>> Sent with Airmail
>>>>>
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution@swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution@swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution@swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


(Tony Allevato) #8

+1. I've had to do this a couple times and ended up wrapping them in string
interpolations, which makes me feel terrible.

路路路

On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution < swift-evolution@swift.org> wrote:

+1

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution < > swift-evolution@swift.org> wrote:

Additive question:

聽聽聽- Can a type instance of a type SomeType.self SomeType.Type be Hashable
聽聽聽?

I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Adrian Zubarev) #9

I鈥檒l do it when we get the go for such additive proposals.

路路路

--
Adrian Zubarev
Sent with Airmail

Am 1. Juli 2016 um 16:15:48, Sean Heber (sean@fifthace.com) schrieb:

+1 here, too. Looking like someone needs to write a full proposal! :stuck_out_tongue:

l8r
Sean

On Jul 1, 2016, at 9:11 AM, Tony Allevato via swift-evolution <swift-evolution@swift.org> wrote:

+1. I've had to do this a couple times and ended up wrapping them in string interpolations, which makes me feel terrible.

On Fri, Jul 1, 2016 at 6:26 AM David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:
+1

On Jul 1, 2016, at 8:20 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

鈥 Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(L Mihalkovic) #10

This is IMHO a loophole in the type system today: '.Type' being a contextual keyword that is part of no protocol, there is no formal definition for what its return type and what can be done is purely driven by the compiler implementation. I used to have my oen bread of typeId until I ran into ObjectIdentifier. This part of te language could use some finishing touches.
Regards
(From mobile)

路路路

On Jul 1, 2016, at 3:20 PM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

Additive question:

Can a type instance of a type SomeType.self SomeType.Type be Hashable?
I really would want to use these in dictionaries or sets :slight_smile:

[Any.Type: ValueType]

Set<Any.Type> // Union type universe

--
Adrian Zubarev
Sent with Airmail
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution