<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 22, 2017, at 2:59 PM, Mike Kluev <<a href="mailto:mike.kluev@gmail.com" class="">mike.kluev@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">on Date: Tue, 21 Nov 2017 22:54:21 -0800 Douglas Gregor <<a href="mailto:dgregor@apple.com" target="_blank" class="">dgregor@apple.com</a>> wrote:<div class=""><br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> On Nov 21, 2017, at 10:48 PM, David Hart <<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>> wrote:<br class="">
><br class="">
> On 22 Nov 2017, at 07:41, Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.<wbr class="">org</a>>> wrote:<br class="">
><br class="">
>><br class="">
>> I think it’s straightforward and less ugly to make structural types allow extensions and protocol conformances.<br class="">
><br class="">
> Can somebody explain to me what is less ugly about that? I would have naturally thought that the language would be simpler as a whole if there only existed nominal types and all structural types were just sugar over them.<br class="">
<br class="">
See Thorsten’s response with, e.g.,<br class="">
<br class="">
Function<Double, InoutParam<String>, Param<Int>><br class="">
<br class="">
which handles “inout” by adding wrappers around the parameter types (which one would have to cope with in any user of Function), but still doesn’t handle argument labels. To handle argument labels, we would need something like strings as generic arguments. We’d also need to handle calling conventions and anything else we invent for function types.<br class="">
<br class=""></blockquote><div class=""><br class=""></div><div class="">can you outline how extensions and protocol conformances might look for structural types? to compare the ugliness of both approaches.</div></div></div></div></div>
</div></blockquote><div><br class=""></div>There are some examples at</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types" class="">https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types</a></div><div><br class=""></div><div>e.g., making all tuples of Equatable elements Equatable (which also mixes in conditional conformances and variadic generics):</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">extension</span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);"><</span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">...</span><span class="pl-c1" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(0, 92, 197);">Elements</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class=""> </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">:</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class=""> </span><span class="pl-c1" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(0, 92, 197);">Equatable</span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">></span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class=""> (</span><span class="pl-c1" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(0, 92, 197);">Elements</span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">...</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class="">) </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(215, 58, 73);">:</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class=""> </span><span class="pl-c1" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(0, 92, 197);">Equatable</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250);" class=""> { </span><span class="pl-c" style="font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; background-color: rgb(246, 248, 250); box-sizing: border-box; color: rgb(106, 115, 125);"><span class="pl-c" style="box-sizing: border-box;">//</span> extending the tuple type "(Elements...)" to be Equatable</span></div><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; word-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; color: rgb(36, 41, 46);" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(106, 115, 125);"></span>}</pre><div class=""><br class=""></div><div>One could imagine adding a “curry” operation to function types:</div><div><br class=""></div><div> extension<Param1, Param2, Result> (Param1, Param2) -> Result {</div><div> var curried: (Param1) -> (Param2) -> Result {</div><div> return { (arg1: Param1) in { (arg2: Param2) in self(arg1, arg2) } }</div><div> }</div><div> }</div><div><br class=""></div><div>Or perhaps making metatypes Hashable so they can be used as keys into a Dictionary:</div><div><br class=""></div><div> extension<T> T.Type: Hashable {</div><div> var hashValue: Int {</div><div> return ObjectIdentifier(self).hashValue</div><div> }</div><div><br class=""></div><div> static func ==(lhs: T.Type, rhs: T.Type) -> Bool { /* standard library magic */ }</div><div> }<br class=""><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""></body></html>