[swift-evolution] Infer types of default function parameters

James Froggatt james.froggatt at me.com
Fri Mar 10 16:55:10 CST 2017


+1 from me, since it's more convenient and an opt-in feature. I'm not sure it's in scope for Swift 4, though, as a purely additive change.

------------ Begin Message ------------ 
Group: gmane.comp.lang.swift.evolution 
MsgID: <CAGJeWTowwVorAyRLN66d4smwwpsqrfCWSO2+krHG-NU8xVJa_Q at mail.gmail.com> 

-1 from me. I prefer explicitness at function boundaries.

On Fri, Mar 10, 2017 at 4:55 PM, David Sweeris via swift-evolution <
swift-evolution-m3FHrko0VLzYtjvyW6yDsg at public.gmane.org> wrote:

>
>On Mar 10, 2017, at 1:40 PM, Kilian Koeltzsch via swift-evolution <
>swift-evolution-m3FHrko0VLzYtjvyW6yDsg at public.gmane.org> wrote:
>
>Hi all,
>
>I sent the message below to swift-users@ ~a day ago, but this might be a
>better place to ask and gather some discussion. It is a rather minor
>suggestion and I'm just looking for some opinions.
>
>Declaring a function that has default parameters currently looks like this:
>
>func foo(bar: String = "baz") {
>print(bar)
>}
>
>Now I'm wondering if there would be any problems if it were possible to
>omit the type annotation for default params and let Swift's type inference
>handle that.
>
>func foo(bar = "baz") {
>print(bar)
>}
>
>It feels to be equivalent to omitting type annotations with variable
>declarations. Obviously more complex types would still require annotations
>being specified. Off the top of my head I can't think of any negative
>ramifications this might bring, be it in simple function/method
>declarations or protocol extensions and elsewhere.
>Any further input or examples for situations where this might cause issues
>would be much appreciated :)
>
>
>Tentatively +1… I still haven’t thought through it as much as I’d like to.
>
>- Dave Sweeris
>
>_______________________________________________
>swift-evolution mailing list
>swift-evolution-m3FHrko0VLzYtjvyW6yDsg at public.gmane.org
>https://lists.swift.org/mailman/listinfo/swift-evolution
>
>



------------- End Message ------------- 



More information about the swift-evolution mailing list