[swift-evolution] Checking in; more thoughts on arrays and variadic generics
Tino Heth
2th at gmx.de
Mon Feb 6 06:35:26 CST 2017
> Consider even if we had compile-time constants like Vector<T, size: Int> — how would that be implemented? What would its backing-type be?
Imho it's very simple — UnsafeMutableBufferPointer would be an obvious choice.
> It would probably want to use that constant to create a fixed-length tuple;
No, it would use that constant to create a fixed-size array of bytes. Don't forget that everything boils down to arrays of bytes (tuples included).
> again, there would be less implementation effort by just having the tuple conform to Collection directly, instead.
Well, it's already trivial to build Vector4<T> instead of Vector<T, size: 4> using current Swift, so imho the step shouldn't be big — and it is obvious to interpret the meaning of this small syntax addition.
Additionally, such an extension of generics would be useful for other things as well.
On the other hand, I think the change you suggest is rather fundamental:
It requires a syntax which is completely new (without an obvious choice on how that syntax should look), and I see no reason for Swift to take a special path.
Most languages I know have a clean distinction between records/structs/tuples and arrays, and this makes sense.
Iterating over the elements in a tuple is like iterating over the properties in a struct or class, and (metaprogramming aside) that feels very strange to me.
- Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170206/469a9dd0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2448 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170206/469a9dd0/attachment.p7s>
More information about the swift-evolution
mailing list