[swift-evolution] [Pitch] Move @noescape
Chris Lattner
clattner at apple.com
Thu Mar 3 18:10:59 CST 2016
> On Mar 3, 2016, at 2:14 PM, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
>
> Will this allow me to write "let myDispatchSync = dispatch_sync as! @noescape () -> Void" ? :-D
Yes, but you need to spell it like this:
let myDispatchSync = dispatch_sync as! ((dispatch_queue_t, @noescape @convention(block) () -> ()) -> Void)
The right answer here is to add @noescape to the imported symbol of course.
-Chris
> Sounds good to me, the old syntax is not necessary anymore.
>
> Jacob
>
> On Thu, Mar 3, 2016 at 2:01 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Chris Eidhof noticed an emergent result of removing our currying syntax: it broke some useful code using @noescape, because we only allowed it on parameter declarations, not on general things-of-function-type. This meant that manually curried code like this:
>
> func curriedFlatMap<A, B>(x: [A]) -> (@noescape A -> [B]) -> [B] {
> return { f in
> x.flatMap(f)
> }
> }
>
> Was rejected. Fixing this was straight-forward (https://github.com/apple/swift/commit/c3c6beac72bc0368030f06d52c46b6444fc48dbd <https://github.com/apple/swift/commit/c3c6beac72bc0368030f06d52c46b6444fc48dbd>), but required @noescape being allowed on arbitrary function types. Now that we have that, these two declarations are equivalent:
>
> func f(@noescape fn : () -> ()) {}
> func f(fn : @noescape () -> ()) {}
>
> I propose that we remove the former syntax, migrating code to the later form. This leads to better consistency between our declarations and types, and follows the precedent of inout. @autoclosure should also probably move as well.
>
> Thoughts?
>
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160303/aa2c09e5/attachment.html>
More information about the swift-evolution
mailing list