[swift-evolution] Sparse (fixed-size) array literal syntax

Jaden Geller jaden.geller at gmail.com
Fri Jun 2 03:06:44 CDT 2017


I don’t know if you’re aware, but you can extend arbitrary nominal types with literal syntax.

```
extension FixedSizedArray: ExpressibleAsDictionaryLiteral { … }
```

Nothing special needs to be done on the implementation side to make this possible. If fixed sized arrays are not nominal types (like tuples, unlike `Array`s), then you will only be able to give this sugar to types that wrap them, not the type itself (w/o special support).

What’s the discussion on enhanced array and dictionary literals? I think I missed that.

Cheers,
Jaden Geller

> On Jun 2, 2017, at 1:02 AM, Daryle Walker <darylew at mac.com> wrote:
> 
> 
>> On Jun 2, 2017, at 3:56 AM, Jaden Geller <jaden.geller at gmail.com> wrote:
>> 
>> Why would this not be possible with fixed sized arrays? Theoretically you could create a type that wrapped a fixed array and make it conform to whatever protocol you want, including the “ExpressibleBy” protocols.
> 
> I DO want it to be possible with future fixed-sized arrays. This is not a user-side question, but implementor-side. I’m asking if the parsing routines for it would conflict with the current array- and dictionary-literal rules, since they will co-exist. If this syntax would make determining whether we have an enhanced array literal or a dictionary literal too hard, then we should change it before anything is finalized.
> 
>> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 



More information about the swift-evolution mailing list