4 ms·
Ocaml arrays are in fact mutable in the same way as Swift arrays. In fact, if I recall right, Ocaml ref's are implemented as single item arrays. I imagine the
by sbmassey 12y ago
Ocaml arrays are in fact mutable in the same way as Swift arrays. In fact, if I recall right, Ocaml ref's are implemented as single item arrays.
I imagine the point is to have a low level type describing an area of contiguous mutable memory, rather than expecting people to use arrays everywhere. Not that I know anything about Swift of course.
- Someone 12y agoThe problem I have with Swift is that Apple minimized the set of containers. There are only two: Dictionary and Array. Array when mutable acts like a list: items are indexed by an integer, and you can replace, add, and remove items. Array, when immutable acts like an area of contiguous memory: items are indexed by an integer, and you can replace items. Dictionary, when mutable, acts like a map: items are indeed by key, and you can replace, add, and remove items. Dictionary, when immutable, acts like a read-only map: items are indexed by key. You cannot add, remove or even replace items. That is inconsistent. I think they would be better of adding List as a third container type, and changing Array to a fixed size (at creation time) container. Immutable Lists and immutable Arrays would behave exactly the same, but I don't see that as a problem. On top of that, they chose to make Arrays and Lists value types, (prematurely?) optimized Arrays (but not Dictionaries) to copy-on-write their data, and decided to make that manual copy-on-write (to ensure that an Array is yours and only yours, you have to call unshare on it) My disclaimer is that I only read the ePub that Apple provided, and somewhat partly so.
- josephlord 12y agoYes, if the Swift had a strong first class list type it wouldn't be a problem but arrays and dictionaries are the only built in collection classes provided.