<div dir="ltr">On 11 October 2017 at 18:30, Mike Kluev <span dir="ltr"><<a href="mailto:mike.kluev@gmail.com" target="_blank">mike.kluev@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">> On 7 Oct 2017, at 04:24, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
><br>
>> These aren’t the forms I was suggesting, what I meant was:<br>
><br>
> extension Int {<br>
> init(randomInRange: Countable{Closed}Range<Int>)<br>
> }<br>
><br>
> which gives:<br>
> let x = Int(randomInRange: 0..<5)<br>
><br>
> The point of this is that you’re producing an Int (or whatever type). Regardless of whether the initializer is failable or not, this is the preferred way of creating a new value with some property: it is an initializer with a label.<br></blockquote><div><br></div><div>or make it a non-initialiser: let x = Int.random or Int.random()</div></div></div></div></blockquote><div><br></div><div>on the positive side would be ability to omit types in many cases:</div><div><br></div><div>foo(_ x: Int) { ... }</div><div><br></div><div>foo(.random) // Int.random inferred</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>have you guys considered: func random<T>(...) -> T</div><div>where it returns a different type based on a context?</div></div></div></div></blockquote><div><br></div><div>or "foo(random())" here, random<Int>() inferred</div><div><br></div><div>the latter case opens wide opportunities for strict type/range checking, e.g.:</div><div><br></div><div>if "angle" is a variable ranging from 0 .. 2*pi then</div><div><br></div><div>angle = random() // is inferred as a 0 .. 2*pi range without me typing anything</div><div><br></div><div>Mike</div><div><br></div></div></div></div>