[swift-evolution] Proposal: Remove implicit tuple splat behavior from function applications

Christopher Whidden christopher.whidden at gmail.com
Wed Jan 27 14:14:59 CST 2016


On Jan 27, 2016, at 12:53 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jan 27, 2016, at 10:46 AM, davesweeris at mac.com <mailto:davesweeris at mac.com> wrote:
>> 
>> <scratches head> Then I’ve misunderstood what splatting was. Is the difference between splatting and what my example does the arguments’ labels?
>> func f(a : Int, _ b : Int) {…}
>> let x = FunctionApplicator((42, b: 19), f) //Would stay legal, because of the "b:"
>> let y = FunctionApplicator((42, 19), f)    //Would become illegal, because there’s no “b:”
> 
> There is no change to either of these.  The later example succeed because of an implicit conversion from "(T,U) -> (T, b: U)”, which is an entirely separate thing.
> 
> The tuple splat behavior I’m talking about can *only* affect call sites that take a single argument.  Both of these examples take two.
> 
> -Chris


I thought Dave had a good point with his first generics example before, but don’t understand what the point was with labeling that he makes above.  However, there is a call site that takes a single argument in his example:
func apply() -> U {
    return function(args)
}

Where args could be a tuple of type T.

I just want to be clear on this.  I’ll put the question a bit more succinctly.  Wouldn’t this functionality be eliminated with the removal of tuple splatting?

func execute<T,U>(f: T->U, args: T) -> U {
    return f(args)
}
execute({$0+1}, args: 5) // Single arg
//6
execute(*, args: (5,5)) // Tuple arg
//25

In this generic function, args can be either a single argument *or* a tuple of arguments that gets applied to the function.

Having said that, I’m not sure what the real use cases or practical value of this is.  Perhaps like a lot of people, I thought Swift’s features like function currying and tuple splatting were *cool* but in reality never used them.  Although I think the generics context is something to consider, I still give the proposal +1.  Tuple splatting looks to be a feature that can’t pull its own weight and has downsides because of syntactic ambiguity.


-Chris Whidden
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160127/32e58086/attachment.html>


More information about the swift-evolution mailing list