[swift-evolution] Changing the curried static methods

Joe Groff jgroff at apple.com
Thu Mar 17 11:17:29 CDT 2016


> On Mar 15, 2016, at 6:03 PM, Stephen Celis <stephen.celis at gmail.com> wrote:
> 
> 
>> On Mar 14, 2016, at 1:09 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Note that there's a proposal open to flatten away the currying altogether:
>> 
>> https://github.com/apple/swift-evolution/blob/master/proposals/0042-flatten-method-types.md
>> 
>> I agree that it would often be more useful to bind the non-self arguments first. Maybe we could provide a different shorthand for that, though; a number of people for instance have suggested `.insetBy(10.0, 10.0)` as a possibility.
> 
> Interesting proposal! Is there a migration path for code that takes advantage of the current currying? The following is a convoluted example, but I've appreciated the flexibility in actual code:
> 
>  func flip<A, B, C>(input: A -> B -> C) -> B -> A -> C {
>    return { b in { a in input(a)(b) } }
>  }
>  let insetBy = flip(CGRect.insetBy)
>  let grow = { insetBy((-$0, -$0)) }
>  grow(50)(.zero)


Well, you could still write a `curry` transform to turn (T, U) -> V into T -> U -> V. IMO, it's much clearer to express these kinds of transforms directly as closure literals than in terms of abstract dataflow transforms like `flip`. { $0.insetBy(-$1, -$1) } is more readily understandable than the above.

-Joe


More information about the swift-evolution mailing list