<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 11 dec. 2015, at 21:30, Gwendal Roué via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Considering the number of times I’ve read about this topic in other languages, I must agree :-)</div><div class=""><br class=""></div><div class="">Yet there are two difficulties:</div><div class=""><br class=""></div><div class="">First, what does Bar get from Double ?</div><div class=""><br class=""></div><div class="">When you say "after creating Bar, I can extend Bar independenly of Double", the problem lies in the meaning of "after". In a language like Ruby, there is an "after", but there is no such clear thing in Swift: modules/packages are compiled as a whole, and module A can extend a type defined the the module B.</div><div class=""><br class=""></div><div class="">More, let’s see what happens below:</div><div class=""><br class=""></div><div class=""><div class="">1<span class="Apple-tab-span" style="white-space:pre">        </span>let d: Double = 1.0</div><div class="">2<span class="Apple-tab-span" style="white-space:pre">        </span>let b: Bar = d<span class="Apple-tab-span" style="white-space:pre">                        </span>// Compiler error, I presume.</div><div class="">3<span class="Apple-tab-span" style="white-space: pre;">        </span>let b: Bar = Bar(d)<span class="Apple-tab-span" style="white-space: pre;">                </span>// Mandatory so that Bar can be put to any use</div><div class="">4<span class="Apple-tab-span" style="white-space:pre">        </span>let b: Bar = 1.0</div></div><div class=""><br class=""></div><div class="">That point 4 is tricky.</div><div class=""><br class=""></div><div class="">If it is not an error, then 2. should succeed as well, don’t you think?</div><div class="">If it is an error, then one may want to add FloatLiteralConvertible to Bar. Oops, Double already implements it.</div></div></div></blockquote>But that is not true. Take this example:</div><div><br class=""></div><div>let x: Int = 3 // Type added for clarity</div><div>let y: Double = x // error</div><div>let z: Double = 3 // ok</div><div><br class=""></div><div>This is exactly why it is Float_Literal_Convertible, it can only convert literals ;).</div><div><br class=""></div><div>Anyway, about the general thing: isn’t this just inheritance, but then for struct types?</div><div>i.e.</div><div><br class=""></div><div>struct Bar : Double {}</div><div><br class=""></div><div>— Nicky</div><div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Hm. I’m afraid I haven’t found the solution :-)</div><div class=""><br class=""></div><div class="">Gwendal Roué</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 11 déc. 2015 à 21:09, Tuur Anton via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
<div class="">
<div class="">//Existing typealias feature.</div><div class="">//Foo acts exactly the same way as Double. It's the same thing.</div><div class="">//Double can be used instead of Foo anywhere.</div><div class="">typealias Foo = Double</div><div class=""><br class=""></div><div class="">//Proposed newtype feature.</div><div class="">//Bar acts exactly the same way as Double and is the same</div><div class="">//thing behind the scenes (until we extend it; see below).</div><div class="">//Trying to use Double instead of Bar will result in a compile-time error.</div><div class="">newtype Bar = Double</div><div class=""><br class=""></div><div class="">Of course, after creating Bar - a "copy" of the type Double, so to speak - I can extend Bar independenly of Double as one would expect.</div><div class=""><br class=""></div><div class="">This would be highly useful.</div><div class=""><br class=""></div><div class="">Your thoughts?</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=GUvuDT95GpxW2sIYHiKg6obX3uIIobaj9awaKuut6Z9P7J-2BsgVSwUjTRK8BQPXpkw8-2BYJdWc0UKVCONS0aE3CbmSncSTVMv33HWIisrxG-2B6V1EOH-2F-2F3zIK-2FXibpWL1OW5DyO-2FXmZU4doUrhlmSsKgMhEn88GsxJLFd2XD-2FCaTim-2FbhDlXmBXrYhQwRm-2BHWqkfdZpjEl5a4U53m63EANkRhKPLorf-2BBQwxvq24nssOT8-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RHl2la-2BftHBRgU0PDt5l8enF-2FEQjC5JypuWCzFZiX9TQbBHdIzMOllS-2BC8HIYne1HQk-2BRJQLySTzV48mPQdfzWfJTAsKg33oQVO6erYkH6cFv01ekZQtrvilB1fWpalpw9jhrrkxCaxXwkVaR-2BX0u2zJnK-2BN4vS5E5BlCyaBKV3KB-2B61XZSBZ-2BTyo8l7aOWyws4-2FPUeMu-2B8l-2F8YsdWBmvxRo-2FYjVpYO5ydw-2FfrbSrW4-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>