[swift-evolution] [Pitch] Moving where Clauses Out Of Parameter Lists
Pyry Jahkola
pyry.jahkola at iki.fi
Wed Apr 6 14:52:38 CDT 2016
Joe,
Just from your experience on this topic, is there any reason not to also move the primary constraints into the trailing `where` clause?
So instead of what you wrote, we'd have it this way:
func foo<T, U>(x: T, y: U) -> Result<T,U>
where T: Foo, U: Bar, T.Foo == U.Bar /*, etc. */
{
}
…as well as:
struct Foo<T, U>
where T: Foo, U: Bar, T.Foo == U.Bar
{
}
Like I said earlier in this thread, I think this would also make the `extension` syntax more uniform with types (by turning generic parameters into strictly locally visible things):
extension Foo<T, U> where U == Baz { // (Could've used X and Y here as well.)
// Now it's clear where the names T and U come from.
var bazzes: [U] { return ... }
}
— Pyry
> I think this is a good idea, though I would put the `where` clause after the function signature:
>
> func foo<T: Foo, U: Bar>(x: T, y: U) -> Result<T,U>
> where T.Foo == U.Bar /*, etc. */
> {
> }
>
> As others noted, it's also appealing to do this for type declarations too:
>
> struct Foo<T: Foo, U: Bar>
> where T.Foo == U.Bar
> {
> }
>
> and that gives a consistent feeling with extensions and protocol declarations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160406/4e7010d7/attachment.html>
More information about the swift-evolution
mailing list