<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="">There’s a good discussion of this <a href="https://devforums.apple.com/thread/263668" class="">here</a>.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 17 Dec 2015, at 16:55, Michael Armstrong 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="">Hi,<br class=""><br class="">My first post to this list so apologies if its not in the correct format or irrelevant / wrong :) Its quite simple, so i'm under the impression that perhaps there is already a very good reason why the below behaviour is on purpose, if this is the case i'd love to learn why, so view it as a proposal / question.<br class=""><br class="">When accessing Array's in Swift (and potentially other types) a Int (signed) is expected, as Array can't have a negative bounds in Swift (as far as i'm aware) would it be sensible to make these UInt? therefor removing the need for tests etc and guarding around negative integers?<br class=""><br class="">For Example:<br class=""><br class=""> let someArray = ["a", "b", "c"]<br class=""> print(someArray.count.dynamicType) // Int<br class=""><br class=""> let someIndex = 1<br class=""> print(someArray[someIndex]) // b<br class=""><br class=""> let anotherIndex : UInt = 1<br class=""> print(someArray[anotherIndex]) // cannot subscript a value of type '[String]' with an index of type 'UInt'<br class=""><br class=""> let invalidIndex = -1<br class=""> print(someArray[invalidIndex]) // Darwin: EXC_BAD_INSTRUCTION / Linux REPL: Error running code: unknown error code 132.<br class=""><br class=""> print (invalidIndex.dynamicType) // Int<br class=""><br class=""> If Array took a UInt, the line 'print(someArray[invalidIndex])' would fail at COMPILE time rather than RUNTIME.<br class=""><br class=""><br class="">Looking at the Swift source there are things like<br class=""><br class=""> _sanityCheck(count >= 0)<br class=""><br class="">Which would be unnecessary if using the type system with UInt.<br class=""><br class="">I'm aware that almost everyone bounds checks Array's before access etc, however is there a reason someone can explain for not using a 'UInt' in these circumstances for 'Array' and other collection types.<br class=""><br class="">Thanks,<br class=""><br class="">Michael<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=""></div></body></html>