> On Feb 18, 2017, at 3:43 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Feb 18, 2017, at 2:41 PM, Matthew Johnson via swift-evolution 
>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>> 
>> There are good reasons a library may not wish to allow users to add 
>> conformances to a protocol.  For example, it may not wish to expose the 
>> conforming concrete types.  While similar behavior could be accomplished 
>> with an enum if cases could be private, that requires an implementation to 
>> use switch statements rather than polymorphism.
> 
> Uh, what? You can expose protocols without exposing the concrete types that 
> conform to them. That’s kind of the whole point of protocols.
> 
> public protocol P {}
> 
> private struct S: P {}
> 
> public var p: P
> 
> reduces to this interface:
> 
> public protocol P {
> }
> 
> 
> public var p: P
> 
> The library can then assign something of type S to the “p” variable, and 
> clients will be able to use it without having access to its concrete type.
> 
> Charles
> 

Sorry, this part was not stated as clearly as it should have been.  What 
intends to say is that the library may wish to not only hide the concrete 
types, but also control the set of types which may conform to the protocol (or 
be associated values of the enum) such that users cannot add to the set of 
types.  I will update the document to more clearly describe this use case.  
Thanks for catching this!

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

Reply via email to