[swift-evolution] [Pitch] Improving capturing semantics of local functions
Slava Pestov
spestov at apple.com
Thu Nov 16 17:47:06 CST 2017
> On Nov 16, 2017, at 3:07 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
>
> Where I am proposing a change is that if a closure with generic arguments is encountered it is transformed into the equivalent struct and the struct is typed as it currently is (or if there is a better implementation something equivalent to this), therefore zero change to the type system.
Since we already have local functions that can capture values and be generic, there’s no need to implement a new mechanism for name mangling or handling of captures.
>
> The changes proposed are a transformation into a struct and name mangling, e.g.:
>
> let increment: <T>(T) throws -> T where T: Numeric = { $0 + 1 }
> let increment = { <T>(n: T) throws -> T where T: Numeric in n + 1 }
> let increment: <T>(T) throws -> T where T: Numeric = { <T>(n: T) throws -> T where T: Numeric in n + 1 }
It sounds like what you’re proposing is essentially a new surface syntax for local functions — since a generic closure would not be a first class value, it could not appear anywhere except for the right hand side of a let binding, right?
Slava
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171116/05a9cca2/attachment.html>
More information about the swift-evolution
mailing list