> On 13 Jun 2016, at 15:52, Erica Sadun <[email protected]> wrote:
>
> I'm not sure what enhancing defaults would look like, especially for
> protocols. Are you suggesting if there's a protocol like:
>
> protocol A {
> func requiredFunction(a, b, c) -> T
> }
>
> that you could then extend
>
> extension A {
> func requiredFunction(a, b = somedefault, c) -> T;
> }
>
> as a declaration without an implementation?
I was thinking more that we could allow a fixed default on protocols where it
makes sense to, for example:
protocol A {
func requiredFunction(a, b = somedefault, c) -> T
}
In this case all conforming types need to specify the same default for absolute
consistency, but this may be a bit divergent from what the OP actually wants, I
just mentioned it because it seemed a bit similar. This would come with the
caveat that most of the time you don’t want to do this (as it could
unnecessarily limit implementations) but it would mean that you know what the
default is for every single conforming type.
Specifically for the OP though an attribute might make more sense, like:
struct Foo : A {
func requiredFunction(a, b = @public somedefault, c) -> T { … }
}
Here the default for b is explicitly declared as public, so would be exposed
via documentation automatically; this would require that it isn’t derived from
anything hidden (allowing this to be checked) and wouldn’t involve exposing
every default value implicitly just for being on a public method as the OP was
questioning.
Just some options anyway, since I don’t think exposing all defaults
automatically is really viable._______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution