[swift-evolution] [swift-evolution-announce] [Review] SE-0089: Replace protocol<P1, P2> syntax with Any<P1, P2>

Thorsten Seitz tseitz42 at icloud.com
Fri May 27 08:15:32 CDT 2016


> Am 27.05.2016 um 14:13 schrieb Vladimir.S <svabox at gmail.com>:
> 
> Support Thorsten's opinion. I believe P & Q much more clear and expressive, don't confuse if we should understand comma separation as 'and' action or 'or' (in case Any<P,Q>) and don't confuse that <P,Q> is not a list of gerenic types. Also such syntax is very lightweight and very readable and understandable.
> 
> There was suggestions to introduce `class` `struct` `enum` keywords in meaning 'any class' 'any strict' 'any enum'. Could this work in the variant with `&` ?
> 
> let b: class & Hashable = ..
> func f(s: struct & Comparable) {…}

Yes, that would be fine.

-Thorsten


> 
> etc
> 
> On 27.05.2016 14:16, Thorsten Seitz via swift-evolution wrote:
>> 
>>> Am 25.05.2016 um 21:22 schrieb Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org>:
>>> 
>>>> But if we are going to remove the ability to use typealiases bound to `Any` in constraints we need to introduce an alternative mechanism for factoring out constraints (hopefully a superior mechanism that can abstract over constraints that relate generic parameters to each other).
>>> 
>>> I could certainly imagine having, for instance, a `constraintalias` keyword:
>>> 
>>> 	constraintalias HashableAndComparable = Hashable, Comparable
>>> 	constraintalias CollectionOfConforming<ElementConstraint> = Collection where .Element: ElementConstraint
>> 
>> The second one is not really a constraintalias but a regular generic typealias making use of an abstracted constraint, isn’t it?
>> 
>> If we use `P & Q` instead of `Any<P, Q>` and just `P` instead of `Any<P>` we not only avoid the confusion between `Any<P>` being the same as `P` in case of P not having associated types or self constraints, we also don’t have to distinguish between using existentials as types and constraints, and we don’t have to introduce something like constraintalias, because typealias is sufficient.
>> 
>> i.e.
>> 
>> typealias HashableAndComparable = Hashable & Comparable
>> 
>> typealias CollectionOfConforming<ElementConstraint> = Collection where .Element: ElementConstraint
>> 
>> let a: HashableAndComparable = 123
>> 
>> let b: Hashable & Comparable = 123
>> 
>> func sum<C: CollectionOfConforming<Integer>>(numbers: C) -> C.Iterator.Element {
>> 	return numbers.reduce(0, combine: +)
>> }
>> 
>> -Thorsten
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 



More information about the swift-evolution mailing list