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

Pyry Jahkola pyry.jahkola at iki.fi
Wed Apr 6 13:42:36 CDT 2016


> The same would work for generic types  too:
> 
> public struct Dictionary<Key, Value>
>     where Key : Hashable
> {
>    ...
> }

And I'm not sure if people feel the same as me, but I haven't been happy with the current way generic arguments (such as Key and Value above) magically appear in type extensions but are inaccessible from anywhere else and can't be made public (`public typealias Key = Key` is an error).

The above syntax would make it possible to use whatever identifiers locally so that it's clear what they are:

extension Dictionary<K, V>
    // (unclear if `where K : Hashable` should be repeated here, though)
{
    ...
}

extension Array<T>
    where T : Comparable
{
    ...
}

extension Array<T>
    where T == String
{
    ...
}

etc.

— Pyry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160406/6d735026/attachment.html>


More information about the swift-evolution mailing list