<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 Mar 16, 2017, at 1:06 PM, David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div 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 class="Apple-interchange-newline">On 16 Mar 2017, at 16:53, Zach Waldowski &lt;<a href="mailto:zach@waldowski.me" class="">zach@waldowski.me</a>&gt; wrote:<br class=""><br class=""></div><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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 16, 2017, at 3:09 AM, David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">2) Libraries like Marshal (<a href="https://github.com/utahiosmac/Marshal" class="">https://github.com/utahiosmac/Marshal</a>) and Unbox (<a href="https://github.com/JohnSundell/Unbox" class="">https://github.com/JohnSundell/Unbox</a>) don’t require the decoding functions to provide the type: those functions are generic on the return turn and it’s automatically inferred:</div><div class=""><br class=""></div><div class="">func decode&lt;T&gt;(key: Key) -&gt; T</div><div class=""><br class=""></div><div class="">self.stringProperty = decode(key: .stringProperty) // correct specialisation of the generic function chosen by the compiler</div><div class=""><br class=""></div><div class="">Is there a reason the proposal did not choose this solution? Its quite sweet.</div></div></div></blockquote><div class=""><br class=""></div><div class="">IMHO those are only “sweet” until you need to decode a value out to something other than a typed value, then it’s ambiguity city.</div></div></div></blockquote><div 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 class=""></div><div 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="">Other than a typed value? Can you give an example?</div></div></blockquote><div><br class=""></div><div>I don’t have an example but I don’t see a problem either. &nbsp;There are two options for specifying the return type manually. &nbsp;We can use the signature you used above and use `as` to specify the expected type:</div><div><br class=""></div><div>let i = decode(.myKey) as Int</div><div><br class=""></div><div>We can also use the type argument but provide a default value:</div><div><br class=""></div><div>func decode&lt;T&gt;(_ key: Key, as type: T.Type = T.self) throws -&gt; T</div><div><br class=""></div><div>let i = decode(key: .myKey, as: Int.self)</div><div><br class=""></div><div>I think the Foundation team should strongly consider one of these signatures and allow us to rely on return type inference when desired. &nbsp;If this isn’t provided by Foundation we’ll see a bunch of wrappers that do this. &nbsp;Why not include it in the standard interface? &nbsp;</div><div><br class=""></div><div>The same argument can be made for providing a subscript instead of or in addition to `decode`. &nbsp;Of course exposing a proper subscript interface isn’t possible until we have throwing subscripts. &nbsp;Decoding is one of the major motivating use cases for throwing subscripts. &nbsp;With Foundation tackling this topic in Swift 4 maybe it would be good to consider bringing throwing subscripts in scope and using them in the interface to KeyedDecodingContainer. &nbsp;</div><div><br class=""></div><div>Subscript with return type inference is the natural interface for a keyed decoder (obviously IMO). &nbsp;If we don’t support this in Foundation we will continue to see 3rd party libraries that do this. &nbsp;I think it would be better to provide the same interface and implementation to everyone directly in Foundation itself.</div><br class=""><blockquote type="cite" class=""><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=""><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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><div class="">There are many ways to solve that, but none of them are conducive to beginners. Using the metatype to seed the generic resolution is the only thing I’d get behind, personally.</div></div><div class=""><br class=""></div><div class=""><div class="">Zach Waldowski</div><div class=""><a href="mailto:zach@waldowski.me" class="">zach@waldowski.me</a></div></div><div class=""><br class=""></div></div></blockquote><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="">_______________________________________________</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=""><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="">swift-evolution mailing list</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=""><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=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></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=""><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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></body></html>