[swift-evolution] Would having "MyType.Protocol" to indicate a type's protocols mess anything up?

Daryle Walker darylew at mac.com
Mon Jul 3 13:43:21 CDT 2017


> On Jul 2, 2017, at 10:15 PM, Christopher Kornher <ckornher at me.com> wrote:
> 
> A full-fledged introspection system should provide this information, which I suppose could be useful for creating proxies through code generation or dynamic Objective-C like features, should they ever be added to the language. Would that be sufficient for your needs? It is not clear to me what problem you are trying to solve.
> 
> Hopefully I won't stir up too much trouble by saying that this kind of capability is very useful in Objective-C for mocking, for example.

I have the proposal for my use case out now at <https://gist.github.com/CTMacUser/c493f775075e946efdcfd85d38473291 <https://gist.github.com/CTMacUser/c493f775075e946efdcfd85d38473291>>.

Look at:

alter MyInt16: Int16, Hashable {
publish Equatable
var hashValue: Int {
return 2000 &+ super.hashValue
}
}

If I wanted to copy Int16 completely, I couldn’t write the full protocol list because it’s open-ended from the user’s perspective due to extensions. However, the list is closed from the compiler/linker’s perspective, so we can synthesize an all-protocol list:

alter MyInt16: Int16, #protocols(Int16), ANewProtocol {
publish #protocols(Int16)
// Define new members here, some of which implement ANewProtocol....
}

Besides this, maybe we could do some analysis using #protocols(MyType).Protocol. (Oh, completely copying Int16 is still useful because functions with them are considered separate overloads, unlike a type-alias.)

I’m not sure what you mean by a full-fledged introspection system, but my current use for it requires a solution that is 100% workable at compile-time.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

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


More information about the swift-evolution mailing list