Opaque protocol ascription in Swift

Originator:jonsterling
Number:rdar://17202906 Date Originated:
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
In Swift, it is possible to adopt a protocol on a structure as follows:

````
protocol Sig {
    typealias A
    let value : A
}

struct X : Sig {
    typealias A = String
    let value = "hello, world"
}
````

It is not possible, however, to erase all the ways in which a structure extends a signature. So, for instance, we have the definitional equality `X.A == String`; it is important for abstraction & modularity to be able to erase this information when desirable.

Steps to Reproduce:
In the following (hypothetical) syntax, we can get this à la Standard ML:

````
struct X :< Sig {
    typealias A = String
    let value = "hello, world"
}
````


Expected Results:
Now, for any `x:X`, we don't have `x.value : String` but rather only `x.value : X.A`. This becomes particularly useful when you have further constraints in the protocol on the abstract type member (like `Equatable` or something).

Actual Results:
Lacking an opaque protocol ascription feature, this kind of abstraction may only be got from upcasting `x:X` to `x:Sig`. It would be ideal if we could enforce abstraction at the level of structures as well.

For a good explanation of how this is useful, Bob Harper's Introduction to Standard ML is a very good text.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!