4 ms·
I guess they think they are cool for being able to provide this feature through a library function rather than a language construct, but someone should tell the
by billyjobob 9y ago
I guess they think they are cool for being able to provide this feature through a library function rather than a language construct, but someone should tell them they really need to add some syntactic sugar that transparently invokes arrayOf while looking nicer.
- mikeash 9y agoIt's worth nothing that Swift literals are mostly library constructs as well. Any type conforming to ArrayLiteralConvertible can be instantiated using [...] syntax, for example. All other literal types (integers, floats, strings, dictionaries, etc.) have their own corresponding protocols you can implement. The only thing that's special for types like Array, Int, or String is that the compiler will automatically infer those types for a literal if there's nothing that indicates otherwise. For example: let x = [1, 2, 3] // produces Array let y: MyType = [1, 2, 3] // produces MyType f([1, 2, 3]) // produces whatever type f() takes