[swift-evolution] [Pitch] Moving where Clauses Out Of Parameter Lists

Sean Heber sean at fifthace.com
Wed Apr 6 14:03:14 CDT 2016

I would think it’d just be unconstrained generic parameters - same as this is now:

func f<A, B>(lhs: A, _ rhs: B) {}

However I can see how it’d certainly be potentially too confusing. It might be worthwhile to retain the brackets, but require type restrictions to be moved to the trailing “where” so that it keeps the <> part as short as possible, so this would be an error:

func f<A: SequenceType, B: Equatable>(lhs: A, _ rhs: B) -> Bool {}

And would have to be written:

func f<A, B>(lhs: A, _ rhs: B) -> Bool where A: SequenceType, B: Equatable {}

Maybe? That’s a bit longer, though. Maybe it’s not worth changing that aspect of it. I like moving “where” to the end, though.


> On Apr 6, 2016, at 1:53 PM, Timothy Wood <tjw at me.com> wrote:
>> On Apr 6, 2016, at 11:48 AM, Sean Heber via swift-evolution <swift-evolution at swift.org> wrote:
>> This almost seems like it could work so that it didn't even need the bracketed parts to be able to figure out the types:
>> func anyCommonElements(lhs: T, _ rhs: U) -> Bool where
>>   T : SequenceType,
>>   U : SequenceType,
>>   T.Generator.Element: Equatable,
>>   T.Generator.Element == U.Generator.Element
>> {}
> ... though if there are no type constraints, this would be ambiguous:
> 	// If there are no know types T and R in scope, is this an error or are T and R assumed to be unconstrained generic parameters?
> 	func f(arg: T) -> R
> -tim

More information about the swift-evolution mailing list