[swift-evolution] [Proposal idea] Support for pure functions
Andrew Trick
atrick at apple.com
Thu Jan 14 11:53:58 CST 2016
> On Jan 14, 2016, at 12:25 AM, Andrew Bennett <cacoyi at gmail.com> wrote:
>
> Good point on `func foo<T>(t: T) {}` being impure without a type constraint, deinit seems to have some interesting consequences.
>
> I've been throwing around the idea of having this notation:
> func myFunc<T,U>(value: T, apply: T -> U) @pure(apply) -> U
> to indicate that myFunc is pure if 'apply' is also pure. Similar to @rethrows.
>
> If it also requires that A has a pure deinit, or further requirements, then perhaps you could use "@pure(value,apply)". In your case you would annotate it like this:
> func foo<T>(t: T) @pure(t) {}
>
> Then the compiler can make foo pure only if T's `deinit` is marked @pure. The issue there is, as you say, if T can be subclassed then those need @pure deinit. This could be solved if the annotation is always inherited, likewise for overrides.
That works for me as long as we can also annotate types to indicate that subclasses and conformances can’t introduce an impure deinit (or introduce class members with impure deinit).
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160114/e9e6f166/attachment.html>
More information about the swift-evolution
mailing list