I quite like this variation, so I’m a +1 for that.

However, I think this would be greatly helped if we could define protocol 
generics more like type generics like so:

        protocol Foo<Element> { … }
        func anyStringFoo(lhs:Foo<String>) { … }

But yeah, for the more complicated cases, it makes a lot of sense to relocate 
the where clause away from the main signature. I’d maybe still allow 
declarations of type though like-so:

        func anyCommonElements<T:SequenceType, U:SequenceType>(lhs:T, _ rhs:U) 
-> Bool
                where T.Generator.Element:Equatable, T.Generator.Element == 
U.Generator.Element

Perhaps allowing us the choice of doing it this way at least.

> On 6 Apr 2016, at 19:35, Pyry Jahkola via swift-evolution 
> <[email protected]> wrote:
> 
>> On 06 Apr 2016, at 21:30, Developer via swift-evolution 
>> <[email protected] <mailto:[email protected]>> 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
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to