[swift-evolution] Infer types of default function parameters

Charles Srstka cocoadev at charlessoft.com
Sat Mar 11 19:32:35 CST 2017

> On Mar 11, 2017, at 3:17 PM, Jaden Geller via swift-evolution <swift-evolution at swift.org> wrote:
> As I understood it, omitting the type would work identically to `let` declarations. A string literal without a type defaults to `String`. Treating it as a generic function is a bad idea IMO.
> I don't think this sugar is worth any amount of added complexity. Most function arguments will have not have default values and this have to continue to declare the type, so this would only be more concise in very few cases. I'd prefer the consistency of always having to explicitly declare the argument type at a function boundary.
> To call a function, you need to know what type to pass in. This becomes more difficult when not make explicit, particularly when a more complicated expression is used as a default. -1

When you declare a property with an inferred type, it shows with the explicit type in the generated interface. So:

public struct S {
	public let foo = 3


public struct S {
	public let foo: Int

I would presume that the same rule would apply to default parameters in function declarations (although to be fair, I’m also uncertain that we actually need this).


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

More information about the swift-evolution mailing list