[swift-evolution] Infer types of default function parameters

David Sweeris davesweeris at mac.com
Sat Mar 11 14:20:03 CST 2017

> On Mar 11, 2017, at 12:57 AM, Jean-Daniel via swift-evolution <swift-evolution at swift.org> wrote:
> -1
> It would be inconsistent to allow it for deterministic literals (String) and not for non deterministic literal (int which can be either a Int, Uint, Float, …)

If I’m not mistaken, even with `bar = “baz”`, `String` is merely the default inferred type. It could be anything that conforms to `ExpressibleByStringLiteral`, right? In that regard, this is kinda just a way to make a function implicitly generic:
func foo(bar = "baz") {…}
func foo<T: ExpressibleByStringLiteral>(bar: T = "baz") {…}

Is there anything we can do with a variable, if all we know of it is that it conforms to `ExpressibleByStringLiteral`? I can’t think of anything… If we had a way to get back the literal string which the variable was initialized with, we could initialize other values with that, but the protocol doesn’t require us to store it. Come to think of it, is there even a way to store a literal value in its “untyped” form? You can declare a variable to of type `IntegerLiteralType`, but the type system then treats it as an `Int`.

So while it looks nice (to me, anyway) I’m not sure you could actually do anything with it. Or am I looking at this wrong?

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

More information about the swift-evolution mailing list