@Lantua's post on the recent property wrappers enhancement thread triggered the following idea for me: would it be desirable to allow users to specify partial type signatures, allowing some portions to be filled in by type inference?
We already sort of have this with generic parameter inference—this would basically be a more configurable version of the same idea.
Possible scenarios where this might be useful:
Specifying an attribute without specifying the entire type (as in the linked post).
ETA: I suppose that the example from the post would actually be spelled as:
@declAttribute var foo: @typeAttribute _ = { ... }
for consistency with the below examples...
Specifying a single generic argument without writing out the entire generic signature:
struct S<T, U> {
init(u: U) {}
}
let s = S<Int, _>(u: someVariableWithComplexType)
Specifying a function argument type which couldn't be inferred:
func foo<T>(_ closure: (T, Int) -> ComplexTypeThatIDontWantToRepeat<Int>) { ... }
func bar(_: Int, _: Int) -> ComplexTypeThatIDontWantToRepeat<Int> { ... }
func bar(_: String, _: Int) -> ComplexTypeThatIDontWantToRepeat<Int> { ... }
foo(bar as (String, _) -> _)
I haven't thought too hard about concrete use cases (or whether the _
spelling would cause issues, but it seems at least plausibly useful and I wanted to hear if anyone had actually ever desired a feature like this!