[swift-evolution] [Proposal idea] Support for pure functions

Joe Groff jgroff at apple.com
Mon Dec 21 15:37:04 CST 2015


> On Dec 21, 2015, at 12:20 PM, T.J. Usiyan via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I have been thinking about this proposal since the list opened up.  I think that @read(none|only) should be considered as an alternative. Just as in clang and the optimizer annotations @read(none) would be the attribute described and @read(only) could read global variables but could not write. Is it possible to generate a runtime error if we guarantee that function A is pure, only to call it and 'find out' that it isn't? If we can, then do try syntax could be considered. 

Another approach here is an effects system. If a pure function were spelled `(T) => U`, then `readonly` could be expressed as `(T) reads => U`, and (T) -> U could remain as a synonym for (T) reads, writes => U, in the spirit of encouraging immutability without punishing mutability.

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151221/38168ef0/attachment.html>


More information about the swift-evolution mailing list