[swift-evolution] [Review] Naming Functions with Argument Labels

Dany St-Amant dsa.mls at icloud.com
Wed Jan 13 19:16:25 CST 2016

Should the proposal include an exclusion list where the disambiguation still need to be resolved by an explicit type declaration. The first is currently hidden in the detailed design, so easy to miss as an exclusion. I compiled the following list based on the previous thread and my understanding of the proposal

Referencing to a parameter less function variant

func foo() { print("foo") }
func foo(_ :Int) { print("foo(_:)") }
let fn: () -> () = foo

Referencing to a function variant which differ only by return type

func foo(_: Int) -> Int { print(" foo -> Int"); return 0 }
func foo(_: Int) -> Bool { print(" foo -> Bool"); return true }
let fn: (Int) -> Int = foo

Referencing to a function variant which have same labels but different parameter types

func foo(_: Int, value: Int) { print("foo Int") }
func foo(_: Int, value: Float) { print("foo Float") }
let fn: (Int, Float) = foo // Still ambiguous reference

The proposal could also highlight that the following is no longer ambiguous.

func foo(_: Int, Celsius: Int) { print("foo Celsius") }
func foo(_: Int, Kelvin: Int) { print("foo Kelvin") }
let fn: (Int, Celsius: Int) = foo // Still/was ambiguous reference
let fn: = foo(_:Celsius:) // Fixed by the proposal

I started to write this note based on the second draft, so I was looking for default parameter example, and there seem to be an issue

func foo(a: Int = 1, b: Int = 2) { print("foo(\(a),\(b))") }
let fn = foo
fn() // error: missing argument for parameter #1 in call
fn(10) // error: cannot convert value of type 'Int' to expected argument type '(Int, b: Int)'
fn(b:20) // error: missing argument for parameter #1 in call
// All the above work when using foo() instead of fn()


> Le 13 janv. 2016 à 12:20, Joe Groff via swift-evolution <swift-evolution at swift.org> a écrit :
>> On Jan 13, 2016, at 9:16 AM, Joe Groff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> Hello Swift community,
>> The review of "Naming Functions with Argument Labels" begins now and runs through January 10th. The proposal is available here:
>> 	https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md <https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md>
> Sorry, Mail mangled the link here, and the review runs through January 18th. Here's the corrected link:
> https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md <https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md>
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160113/26a889f9/attachment.html>

More information about the swift-evolution mailing list