[swift-evolution] 'T != Type' in where clause
David Sweeris
davesweeris at mac.com
Wed Mar 1 21:06:24 CST 2017
> On Mar 1, 2017, at 18:55, Joe Groff <jgroff at apple.com> wrote:
>
>
>> On Mar 1, 2017, at 5:27 PM, David Sweeris <davesweeris at mac.com> wrote:
>>
>>
>>> On Feb 28, 2017, at 09:01, Joe Groff <jgroff at apple.com> wrote:
>>>
>>>
>>>> On Feb 27, 2017, at 10:21 PM, David Sweeris via swift-evolution <swift-evolution at swift.org> wrote:
>>>>
>>>> + all the 1s, along with something like "where !(T: Foo)"
>>>
>>> This is an impossible constraint to enforce, since anyone can extend any type to conform to Foo.
>>
>> Only for protocols, right? I mean, as far as I know, you can’t declare a superclass in an extension.
>>
>> I've been thinking about this for, well, about a day and a half, and I don't understand why it’s a problem. Wouldn’t any concrete type’s conformance propagate through the type system? How else would generic functions deal with types being extended outside the generic function’s module?
>
> Protocol conformances are not intrinsic to the type in Swift. They're effectively independent parameters to generic contexts that require them. The caller from outside the generic function's model is responsible for choosing a conformance to pass. There's no way to statically enforce that no such conformance exists, and there's usually a better way to model things.
Ooohhhh.... ok, thanks :-)
From a technical PoV, could we allow "where !(T: SomeClass)", since that doesn't involve protocols?
- Dave Sweeris
More information about the swift-evolution
mailing list