<div dir="ltr">Commented on the proposal but realize that it might be better to reply here. <div><br></div><div>For clarification: when you say "deprecate typealias" do you mean only in the context of associated types or in the language as a whole?</div><div> </div><div>I also thought it might make sense to add to the proposal a disabling of the "default" behavior that is currently allowed for type aliases in protocols:</div><div><br></div><div>protocol Prot {</div><div> associated Container: SequenceType</div><div> associated Element = Container.Generator.Element // should be illegal</div><div>}</div><div><br></div><div>Instead, if you actually want the semantics of an additional associated type with a default (but overridable) value, you should use a protocol extension. (Which means that associated ____ = ____ would be allowed in protocol extensions, but not associated ____ : _____ or associated ____ : ____ = _____.) Does that sound right?</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 6, 2015 at 10:32 AM, Loïc Lecrenier <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Well, I went ahead and created a pull request :)<br>
<br>
I also included a “proposed approach” section, where I propose to deprecate<br>
the `typealias` keyword for Swift 2.2, and replace it entirely for Swift 3.0.<br>
<br>
Does anyone have any thought on that? This is a bit aggressive, but I think it’s worth it.<br>
It is actually the same approach Erica proposed for removing C for-loops.<br>
<span class="HOEnZb"><font color="#888888"><br>
Loïc<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Dec 6, 2015, at 1:12 PM, Loïc Lecrenier <<a href="mailto:loiclecrenier@icloud.com">loiclecrenier@icloud.com</a>> wrote:<br>
><br>
> I have drafted a formal proposal here: <a href="https://gist.github.com/loiclec/22459d230a21dbcb81fc" rel="noreferrer" target="_blank">https://gist.github.com/loiclec/22459d230a21dbcb81fc</a><br>
> Would love to receive feedback from the community on it, I am particularly worried about the correctness of the terms I used.<br>
> Should I make a pull request to swift-evolution now, or should we continue the conversation here?<br>
><br>
> Thanks,<br>
><br>
> Loïc<br>
><br>
> (and sorry about emailing you on Sunday 😇 )<br>
><br>
>> On Dec 6, 2015, at 1:48 AM, John McCall <<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>> wrote:<br>
>><br>
>>> On Dec 5, 2015, at 4:35 PM, Loïc Lecrenier via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>>> Hi everyone :)<br>
>>><br>
>>> I propose introducing a new "associated_type" keyword that will replace "typealias" for declaring associated types in protocols.<br>
>>> I remember being confused by associated types when I started using Swift, and I think one reason why was the use of the typealias keyword to define them.<br>
>>> One reason was that I thought I knew what typealias did, and so I didn't stop to learn what it did inside a protocol. An other reason was the difficulty of finding help when searching for "typealias" instead of "associated types".<br>
>>> Then, when I thought I understood it, I started building an excessively protocol-oriented program as an exercise. And I still lost a lot of time fighting Swift by trying to use "real" typealias-es inside of protocols.<br>
>>><br>
>>> Conceptually, I had something like this:<br>
>>><br>
>>> protocol ProtA {<br>
>>> typealias Container : SequenceType<br>
>>> }<br>
>>> protocol ProtB {<br>
>>> typealias AnOtherAssocType : ProtA<br>
>>> func foo(x: AnOtherAssocType.Container.Generator.Element, y: AnOtherAssocType.Container.Generator.Element) -> AnOtherAssocType.Container.Generator.Element<br>
>>> }<br>
>>><br>
>>> The function foo is very difficult to read, so I wanted to use a shortcut to Element by doing this:<br>
>>><br>
>>> protocol ProtB {<br>
>>> typealias A : ProtA<br>
>>> typealias Element = A.Container.Generator.Element<br>
>>> func foo(x: Element, y: Element) -> Element<br>
>>> }<br>
>>><br>
>>> But by doing so, I didn't create a shortcut to Element, but an associated type with a default value of Element. (right?)<br>
>>> Then I tried to write extensions to ProtB where Element conforms to, say, Equatable, and couldn't make it work because A.Container.Generator.Element didn't conform to Equatable.<br>
>>><br>
>>> So, that was a rather long explanation of the reasons I think we should replace the typealias keyword by associated_type, and allow "real" typealias-es inside protocols.<br>
>><br>
>> I think this is a great idea; re-using typealias for associated types was a mistake.<br>
>><br>
>> John.<br>
>><br>
>>><br>
>>> Ideally, I would write<br>
>>><br>
>>> protocol ProtB {<br>
>>> associated_type AnOtherAssocType : ProtA<br>
>>> typealias Element = AnOtherAssocType.Container.Generator.Element<br>
>>> func foo(x: Element, y: Element) -> Element<br>
>>> }<br>
>>><br>
>>> and it would be exactly the same as<br>
>>><br>
>>> protocol ProtB {<br>
>>> associated_type AnOtherAssocType : ProtA<br>
>>> func foo(x: A.Container.Generator.Element, y: A.Container.Generator.Element) -> A.Container.Generator.Element<br>
>>> }<br>
>>><br>
>>> There are probably some problems created by this proposal, but right now I can't see any :/<br>
>>><br>
>>> Thanks,<br>
>>><br>
>>> Loïc<br>
>>> _______________________________________________<br>
>>> swift-evolution mailing list<br>
>>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
>>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>