> On Jun 23, 2017, at 9:29 AM, Nevin Brackett-Rozinsky 
> <[email protected]> wrote:
> 
> This sounds similar to lenses. Have you looked at previous lens discussions 
> on-list?

I had no idea what a lens is. Nor was is easy to figure out since I can’t read 
Scala, JavaScript, or Haskell. From what I can grok from those papers, I’m 
guessing it’s like C++’s pointer-to-member, but it’s more like a group of them 
forming an access chain from a source object to a (possibly nested) sub-object. 
It seems like a functional programming thing.

>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:

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006663.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006663.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/019138.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/019138.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005236.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005236.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160307/012541.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160307/012541.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160627/022479.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160627/022479.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151221/004555.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151221/004555.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160801/025882.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160801/025882.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006262.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006262.html>
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161212/029531.html
 
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161212/029531.html>

The “Lenses in Swift” video is actually at 
<https://www.youtube.com/watch?v=ofjehH9f-CU 
<https://www.youtube.com/watch?v=ofjehH9f-CU>>.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to