<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 Feb 18, 2017, at 7:23 AM, Milos Jakovljevic 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=""><div class="">Are there are any plans of adding implicit conversion between primitive types?<br class=""><br class="">For example<br class=""><br class="">var float = 5.0<br class=""><br class="">func accept(float: Float) {<br class=""> print("this is \(float)")<br class="">}<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>I recently posted a manifesto that covers value subtyping: <a href="https://gist.github.com/anandabits/5b7f8e3836387e893e3a1197a4bf144d" class="">https://gist.github.com/anandabits/5b7f8e3836387e893e3a1197a4bf144d</a>. My opinion is that this is the best way to introduce implicit conversions of the kind you’re talking about here.</div><div><br class=""></div><div>That said, without changing how Swift handles type inference for unannotated assignments from literals your example would not work with value subtyping. This is a good thing! It is because the type of `float` is actually `Double` which can represent many values that are not possible to represent with a value of type `Float`. </div><div><br class=""></div><div>In order to allow this to work the way you intuitively want we would need `float` to be assigned some kind of `***Literal` type that keeps track of the fact that the value is small enough to be represented by `Float`. This `***Literal` type would be a subtype of `Float`.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">This will raise a warning that double cannot be cast to float. Which is really frustrating since i always have to add type explicitly or cast it to Float. <br class=""><br class="">I would also like to propose to add "f" modifier for floats.<br class="">Any thoughts?<br class=""><br class="">Best,<br class="">Milos Jakovljevic<br class="">_______________________________________________<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></div></blockquote></div><br class=""></body></html>