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

Milos Rankovic milos at milos-and-slavica.net
Wed Apr 6 14:01:19 CDT 2016


With `where` at the end, the Standard Library function:

	public func != <
		A : Equatable, 
		B : Equatable, 
		C : Equatable, 
		D : Equatable, 
		E : Equatable, 
		F : Equatable
	> (lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool

becomes:

	public func != (lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool where <
		A : Equatable,
		B : Equatable,
		C : Equatable,
		D : Equatable,
		E : Equatable,
		F : Equatable
	>
milos

> On 6 Apr 2016, at 19:35, Pyry Jahkola via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On 06 Apr 2016, at 21:30, Developer via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> If you've ever gotten to the point where you have a sufficiently generic interface to a thing and you need to constrain it, possibly in an extension, maybe for a generic free function or operator, you know what a pain the syntax can be for these kinds of operations.
> 
> +1 already!
> 
>> Or, if you're feeling ambitious, even
>> 
>> func anyCommonElements <T, U>
>> where T : SequenceType, U : SequenceType,
>> T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element
>> (lhs: T, _ rhs: U) -> Bool
> 
> I would actually move them as far as after everything else, and right before the definition body. For the above function that would mean:
> 
> func anyCommonElements<T, U>(lhs: T, _ rhs: U) -> Bool
>     where T : SequenceType,
>           U : SequenceType,
>           T.Generator.Element: Equatable,
>           T.Generator.Element == U.Generator.Element
> {
>     ...
> }
> 
> That would make the definition look closer to what the call site looks like.
> 
> The same would work for generic types  too:
> 
> public struct Dictionary<Key, Value>
>     where Key : Hashable
> {
>    ...
> }
> 
> — Pyry
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160406/1aa79cd7/attachment.html>


More information about the swift-evolution mailing list