<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 9 Jun 2016, at 17:11, Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">on Thu Jun 09 2016, Haravikk <</span><a href="http://swift-evolution-at-haravikk.me/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution-AT-haravikk.me</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class="">On 8 Jun 2016, at 20:53, Dave Abrahams via swift-evolution<br class=""></blockquote><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">on Wed Jun 08 2016, Haravikk <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></blockquote></blockquote><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">But those shouldn't be the public names. Perhaps s/box/wrap/ ?<br class=""></blockquote></blockquote><br class="">True! So I’m thinking I’ll try to come up with a basic proposal soon,<br class="">I’m just thinking about how this would be implemented. For example, it<br class="">may make sense to do this as a protocol that AnyIndex (and other<br class="">suitable types) can just conform to like so:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>protocol Unwrappable {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>associatedtype UnwrappedType<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>func unwrap<T:UnwrappedType>() -> T?<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>func unsafeUnwrap<T:UnwrappedType>() -> T<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<br class=""><br class="">I’ve kept the ability to specify a root type that unwrapping can<br class="">produce, i.e- Comparable in the case of AnyIndex. Not too happy with<br class="">the name of UnwrappedType, since it’s not intended to be the exact<br class="">type in most cases,<span class="Apple-converted-space"> </span><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Examples please?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Unfortunately I can’t actually seem to get the above protocol to work, Swift won’t accept the associated type on the generic constraints for the methods, it complains of it being a non-class/non-protocol type. These kinds of tricky generics are very much not a strength of my Swift programming abilities =)</div><div><br class=""></div><div>The advantage of being able to declare a base type however is that it helps to disambiguate overloads. For example, consider unwrapping on AnyIndex using the following method:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public struct AnyIndex : Comparable {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>public func unsafeUnwrap<T:Comparable>() -> T</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><br class=""></div><div>I then get myself an AnyIndex and decide I’d like to use it in a subscript like so:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let value = myDictionary[myIndex.unsafeUnwrap()]</font></div><div><br class=""></div><div>Since the unwrapped type is known to at least be of type Comparable, it’s obvious to the compiler which subscript I mean. If however no minimum conformance is provided (i.e- the above method is unsafeUnwrap<T>() -> T) then there are three possibilities (Index, Range and Key, since it’s a dictionary) so it produces an error.</div><div>It can still be used by assigning the unwrapped value to a variable with explicit type, but that’s a bit more verbose than I was hoping for.</div><div>Of course it can still fail if my AnyIndex isn’t wrapping a DictionaryIndex, but the extra type information at least prevents me from using the unwrapping somewhere that a Comparable can’t possibly be used.</div><div><br class=""></div><div>So in my code this so far means I’m having to stick with adding the methods directly to my AnyIndex substitute rather than to a protocol, as I can put the restriction on it this way.</div><div><br class=""></div><div>Like I say though, complex generic conformance is something I’m still ropey on (yet I seem to keep finding myself cases that need it) so it’s possible there’s a way to do this that I just can’t think of, or perhaps there are some features on their way that would enable this to work as I’m hoping?</div></div></body></html>