[swift-evolution] 'T != Type' in where clause
dgregor at apple.com
Tue Feb 28 16:15:01 CST 2017
> On Feb 28, 2017, at 2:00 PM, David Hart <david at hartbit.com> wrote:
>> On 28 Feb 2017, at 22:39, Douglas Gregor via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Feb 27, 2017, at 11:21 PM, Nicolas Fezans via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> I would also welcome to be able to use "or" and "and" logical operators (not only the not operator) on these constraints.
>> You already have “and’ constraints: it’s what you get out of the comma-separated list of constraints in a where clause, or the “&” composition syntax.
>>> I have sometimes generic functions whose code is identical but is written twice: first with 'where T=P1' and then with 'where T=P2', being able to write for instance 'where T=(P1 or P2)' would be very handy IMO.
>>> One could often argue that additional protocols and extensions could be defined as a workaround to the situation I just mentioned but it seems often a bit of an overkill to me when you only have a couple of functions with that combination of requirements.
>> “Or” constraints are a nonstarter for me, because you can’t meaningfully type-check a generic function that uses “or” constraints: the problem goes exponential in the number of “or” constraints and the meaning of the function can change considerably depending on which set of terms are satisfied—in which case you have ambiguities again!
>> Whenever this topic comes up, I like to point people at:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2161.pdf <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2161.pdf>
> Should we also follow Recommendation #2 and revert the P1 & P2 change to return to Any<P1, P2> :) Half-joking.
That line of argument got thoroughly shot down in the core team meeting when we discussed the introduction of the & operator for types.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution