<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=""><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 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><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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>