[swift-evolution] Properties on Default Protocol Implementations
Matthew Johnson
matthew at anandabits.com
Tue Jan 12 08:24:11 CST 2016
Sent from my iPad
On Jan 12, 2016, at 1:11 AM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> An automatic approach brings hesitation to me, because I don’t want it to be the difference between:
>>
>> protocol P {
>> var x : Int { get }
>> }
>>
>> and:
>>
>> protocol P {
>> var x : Int
>> }
>>
>> Did I want a PwS there, or did I just forget {get/set}?
>
> If we're going to start adding concrete things to protocols—not just stored properties, but (drawing on other proposals) perhaps also default implementations, final members, factory initializers, etc.—perhaps we should start marking the things that *aren't* concrete with `required`.
>
> Currently:
>
> public protocol Strideable : Comparable, _Strideable {
> associatedtype Stride : SignedNumberType
> @warn_unused_result
> public func distanceTo(other: Self) -> Self.Stride
> @warn_unused_result
> public func advancedBy(n: Self.Stride) -> Self
> }
>
> extension Strideable {
> @warn_unused_result
> public func stride(to end: Self, by stride: Self.Stride) -> StrideTo<Self> {
> /* implementation here */
> }
> }
>
> extension Strideable {
> @warn_unused_result
> public func stride(through end: Self, by stride: Self.Stride) -> StrideThrough<Self> {
> /* implementation here */
> }
> }
>
> Future:
>
> public protocol Strideable : Comparable, _Strideable {
> associatedtype Stride : SignedNumberType
> @warn_unused_result
> required public func distanceTo(other: Self) -> Self.Stride
> @warn_unused_result
> required public func advancedBy(n: Self.Stride) -> Self
>
> @warn_unused_result
> final public func stride(to end: Self, by stride: Self.Stride) -> StrideTo<Self> {
> /* implementation here */
> }
>
> @warn_unused_result
> final public func stride(through end: Self, by stride: Self.Stride) -> StrideThrough<Self> {
> /* implementation here */
> }
> }
Not sure which should be the default (required or not required), but I agree that the minimum required members for conformance should be much more clear than it is in protocol declarations today.
Matthew
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> 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