On Aug 10, 2014, at 14:39 , Roland King <r...@rols.org> wrote:

> I haven't yet understood why there are two different syntaxes for 
> class/function generics, with the <X,Y,Z> syntax but protocols are unadorned 
> but have associated types. Naively I would have expected both to look the 
> same, with parameters in angle brackets

Well, the semantics *are* different. Each “parameterized” class is a different 
type, but all “parameterized” protocols (of the same name, I mean) are the same 
type. A while back I did start to consider what a "generic protocol” might 
mean, instead of a type-associated one, but my head immediately started to hurt.

> I think it's time to resurrect the Swift book and read the second 1/2 of it 
> more slowly than I did the first time.

I wouldn’t hold out much hope. The book just skates over the surface. In 
particular, it seems to me that what it says about associated types in 
protocols is either pure nonsense, or is missing a couple of key facts.

[Specifically, I suspect that a ‘typealias’ in a protocol must either get bound 
to a specific auxiliary type in an inheritor of the protocol, otherwise it 
defaults to being bound to the inheritor’s type (i.e. ‘Self’). However, it 
looks to me that the specific binding is generally by inference, and so is 
indistinguishable syntactically from the default binding. The book describes 
one thing, but links to an example that shows the other.

There’s also something going on with the silly-looking generic specifier ‘<S: T 
where T == T>’ that appears in some of Swift’s internal class declarations, but 
it seems to be meaningful in relation to protocols in some non-obvious way.]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to