[swift-evolution] Default Generic Arguments

T.J. Usiyan griotspeak at gmail.com
Mon Jan 23 16:07:49 CST 2017


A `Parser<Output = Void, StringType = String> where StringType :
ParsableStringType`

`Void` is a fine default (somewhat questionable but follow me) because
`Void?` ends up having the same info as a boolean which means that our
Parser is, effectively, a recognizer. Thinking about it,
`GrammarRecognizer<StringType = String> where StringType :
ParsableStringType` sidesteps the issue entirely and gives a second example
of when we could fill all type parameters.

On Mon, Jan 23, 2017 at 4:32 PM, David Waite <david at alkaline-solutions.com>
wrote:

> You do have empty angle brackets today, which indicate an inferred generic
> argument rather than a defaulted generic argument. See:
>
>   1> let a = 1
> a: Int = 1
>   2> let b:Optional = a
> b: Int? = 1
>
> If Swift had defined Optional as Optional<Wrapped = Any>, statement 2
> would be ambiguous.
>
> I have a hard time coming up with a realistic generic which can have every
> argument defaulted. If someone can’t give a real-world example, I would
> require empty angle brackets just to differentiate defaulted vs inferred
> arguments.
>
> -DW
>
> On Jan 23, 2017, at 12:25 PM, T.J. Usiyan via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> I am against requiring empty angle brackets. I could live with it either
> way, but I think that one reason to provide default types is to hide the
> detail that there is a type parameter until such a time as it is needed.
> Empty angle brackets call attention to the feature in a manner that
> discards any possible gains on this front. Empty angle brackets would be
> confusing to explain to someone new to the language and–more
> importantly–shouldn't be necessary to explain in the "falling back to
> defaults" case.
>
> On Mon, Jan 23, 2017 at 1:41 PM, Trent Nadeau via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> The proposal looks good to me with one possible concern. I'm leaning
>> toward types that use the defaults should still require the angle brackets,
>> X<>. This makes it clear that you're using a generic type. That leads me to
>> think that the examples Doug gave should be an error as the explicit types
>> on the `let`s should either be omitted completely or fully specified (as
>> X<>, X<Double>, X<Int>, etc.).
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170123/28cd20e7/attachment.html>


More information about the swift-evolution mailing list