[swift-evolution] [Pitch] Support for pure functions. Part n + 1.

David Sweeris davesweeris at mac.com
Thu Feb 16 15:24:54 CST 2017


> On Feb 16, 2017, at 13:10, Dennis Weissmann via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Secondly, are they inherited? So if ClassA has a pure function a(), can I override it in subclass ClassB: ClassA to be impure? (I think no)

I would agree. IIUC, the "pureness" of A's implementation of a() becomes a moot point if B's implementation doesn't have to have at least as strong of a constraint,  because otherwise all the optimizations that the compiler makes would break as soon as someone passes a B in instead of an A.

> Can I annotate a function in a protocol to force it to be pure? (not sure about this one)

I would say yes, for similar reasons: if the attribute doesn't hold for *all* implementations, the compiler can't assume it holds for any. At least not with the way generics work now, IIUC.

- Dave Sweeris.


More information about the swift-evolution mailing list