[swift-evolution] Default implementation for protocols

Chris Lattner clattner at apple.com
Sat Jan 30 23:10:54 CST 2016


> On Jan 30, 2016, at 4:48 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Proposal
> =======
> Allow protocols to define a default implementation, e.g.:
> 
>   protocol Complex {
>     default var re: Double = 0
>     default var im: Double = 0
>     var mag: Double { return sqrt(re * re + im * im) }
>     // ...
>   }

Hi Howard,

This is a desired feature, but a surprising amount of implementation effort blocks “just doing it”.  We hope that this will happen in Swift 3, but we’ll see how things work out with the other generics system improvements.

-Chris



More information about the swift-evolution mailing list