<div dir="ltr">My assumption is that the proposed newtype simply adopts the storage and any available functions, operators, and extensions available on the original type.<div><br></div><div>Extensions on Double are available to Double and Bar. Extensions explicitly on Bar are only available on Bar. </div><div><br></div><div>That said, I'm not sure this is worth the complexity when you can just wrap a Double inside your own struct Bar {} and get most of the benefits.</div><div><br></div><div><br></div><div>Russ Bishop</div><div><a href="http://russbishop.net">russbishop.net</a></div><div><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 12:30 PM, Gwendal Roué <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Considering the number of times I’ve read about this topic in other languages, I must agree :-)</div><div><br></div><div>Yet there are two difficulties:</div><div><br></div><div>First, what does Bar get from Double ?</div><div><br></div><div>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><br></div><div>More, let’s see what happens below:</div><div><br></div><div><div>1<span style="white-space:pre-wrap">        </span>let d: Double = 1.0</div><div>2<span style="white-space:pre-wrap">        </span>let b: Bar = d<span style="white-space:pre-wrap">                        </span>// Compiler error, I presume.</div><div>3<span style="white-space:pre-wrap">        </span>let b: Bar = Bar(d)<span style="white-space:pre-wrap">                </span>// Mandatory so that Bar can be put to any use</div><div>4<span style="white-space:pre-wrap">        </span>let b: Bar = 1.0</div></div><div><br></div><div>That point 4 is tricky.</div><div><br></div><div>If it is not an error, then 2. should succeed as well, don’t you think?</div><div>If it is an error, then one may want to add FloatLiteralConvertible to Bar. Oops, Double already implements it.</div><div><br></div><div>Hm. I’m afraid I haven’t found the solution :-)</div><div><br></div><div>Gwendal Roué</div><br><div><blockquote type="cite"><div><div class="h5"><div>Le 11 déc. 2015 à 21:09, Tuur Anton via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br></div></div><div><div><div class="h5">
<div>
<div>//Existing typealias feature.</div><div>//Foo acts exactly the same way as Double. It's the same thing.</div><div>//Double can be used instead of Foo anywhere.</div><div>typealias Foo = Double</div><div><br></div><div>//Proposed newtype feature.</div><div>//Bar acts exactly the same way as Double and is the same</div><div>//thing behind the scenes (until we extend it; see below).</div><div>//Trying to use Double instead of Bar will result in a compile-time error.</div><div>newtype Bar = Double</div><div><br></div><div>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><br></div><div>This would be highly useful.</div><div><br></div><div>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="min-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">
</div></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=mwZnBoTTfz9g3rSWkUxrLKAH2MNEYeus7S7xlan1SLoMWS6brArWKvoQ8n5wNhUuOQ-2BRL2i2qT9ZPJvpJAjcBJ3Q-2BnvGfOOGu4WI-2BoV8MUsec-2BmDe6oM2x8CDAldhIEGjx66SIAvm7gSu2cgeK35EXcxH-2FPXe60VtSsPBidhBypZ6TQbfkR1-2BnbbobFPr5fBQNE5Vh3BfMxG8CPH-2BEf4mYN8-2B1kfSoWl9n24kuO16gI-3D" alt="" width="1" height="1" border="0" style="min-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">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div></div>