[swift-evolution] [Pitch] Object aliases
darylew at mac.com
Sun Jun 25 01:40:55 CDT 2017
> On Jun 23, 2017, at 9:29 AM, Nevin Brackett-Rozinsky <nevin.brackettrozinsky at gmail.com> wrote:
> This sounds similar to lenses. Have you looked at previous lens discussions on-list?
From a high-level view, a poser is a kind of a lens. But the low-level details are completely different.
* A lens is a first-class type, probably part of a Standard Library. Posers are symbolic substitution; they’re deliberately not first-class types.
* As a first-class type, lenses have data, indicating the path from source to sub-object. There is no data for a poser, since the concept is realized during translation.
* A lens, a far as I understand, targets a sub-object. A poser can target the entirety of a named object.
* A poser can cover substituting an object of one type for a layout-compatible type (including future strong type-aliases). Lenses don’t cover this use case.
* A poser’s purpose is to defeat copy-in/out semantics with reference semantics. How lenses work on copy-in/out vs. reference is unspecified.
Swift tries to avoid direct reference semantics, and does two-way object passing as (or as-if) copy-in & copy-out. This avoids having to do the pessimizations needed for safety when one object reference may alias another. Posers are limited to minimize these anti-optimizations. Posers can only be implementation aids for functions; they cannot be globals nor a property/associated-value (not the case for lenses since they’re first-class types). Posers can only alias a (sub-)block of statically determined memory (not the case for lenses either). Posers are not passed a function arguments or returns; the original object is instead.
Something I like about the poser syntax is that we could extend it to actual lenses someday (when we can make pointer-to-member expressions).
Oh, some previous discussions are:
The “Lenses in Swift” video is actually at <https://www.youtube.com/watch?v=ofjehH9f-CU <https://www.youtube.com/watch?v=ofjehH9f-CU>>.
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution