[swift-evolution] Tuples as RawRepresentable
David Sweeris
davesweeris at mac.com
Fri Oct 14 03:49:13 CDT 2016
I'm very much in favor of the functionality, but I don't think the implementation should rely on compiler magic.
- Dave Sweeris
> On Oct 14, 2016, at 03:24, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>
> Following on from discussion about stored properties for enums, I've decided to split off discussion about the possibility of enabling tuples as raw values.
>
> Currently to enable multi-part raw values we need to define a struct that conforms to RawRepresentable; this involves a lot of boilerplate however, and seems like exactly the kind of thing that tuples are ideally suited towards simplifying.
>
> To make tuples automatically conform to RawRepresentable will likely require some compiler magic, but I think it's worth doing, and should be doable with the following additions:
>
> A TupleType protocol (uncertain of correct name for it) to which all specific tuple types will automatically conform, and to which user-defined types may not. This is simply a marker type for now (no methods etc.), as it is essentially just to enable the following:
> An ExpressableAsTuple protocol, following the same style as other ExpressableAs* protocols, with the associated type conforming to TupleType, thus requiring that it be a specific tuple definition. All specific tuple types are automatically expressible as themselves.
> All tuples will then conform to RawRepresentable, simply returning themselves as their raw value. This may require some magic as well, since I don't know if we want tuples to gain a .rawValue property or not, so could be exposed only when handling them as RawRepresentable specifically?
>
> With ExpressableAsTuple recognised as RawRepresentable, I believe this should satisfy all requirements such that enums, and other types requiring literals, will be able to accept tuples in addition to the types that they currently do.
>
> I think I've covered the requirements here, and I'm hoping someone can confirm if this looks correct. Of course I'm open to any other suggestions on how we might enable tuples as literals, especially if there's an easier way!
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161014/e3167e2f/attachment.html>
More information about the swift-evolution
mailing list