<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 23, 2016, at 11:19 AM, Patrick Smith &lt;<a href="mailto:pgwsmith@gmail.com" class="">pgwsmith@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I just want to highlight the Photoshop history example. I agree you’d want as much state and memory shared between steps in the history.</div><div class=""><br class=""></div><div class="">However, I see nothing wrong with having pointers to pixel buffer, and that affecting the ‘purity’ of the state. </div></div></div></blockquote><div><br class=""></div><div>I don’t have a problem with pointers to pixel buffers. &nbsp;What I have a problem with is pointers to shared mutable state. &nbsp;All you need to do is implement a value type that wraps the pointer and performs CoW before updating. &nbsp;Now you have an efficient pixel buffer that is a pure value type.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The way Photoshop’s history is implemented, is every image is broken up into tiles. Changes are recorded only within touched tiles. (<a href="http://www.photoshopforphotographers.com/CC_2013/Help_guide/tp/History_palette.html" class="">http://www.photoshopforphotographers.com/CC_2013/Help_guide/tp/History_palette.html</a>) This improves memory usage compared to a single pixel buffer. </div></div></div></blockquote><div><br class=""></div><div>Yep, I know how it is implemented and believe I described this upthread. &nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">With a graphics programming workflow, say where a background thread or the GPU is involved, the contents of those pixel buffers are going to change independently to the history stack. I think there would no problem for the history steps to have pointers to their mutable pixel buffers. Once the thread/GPU has finished processing changes within a step’s pixel buffer, it is ‘sealed’ say with a flag, and can’t be mutated later.</div></div></div></blockquote><div><br class=""></div><div>If you don’t know what the new value is synchronously then it certainly isn’t quite as simple. &nbsp;But you can still encapsulate this in a type that holds the pointer, performs CoW when necessary, and ensures that the pixel buffer isn’t written to other than by the job that is processing the pixels for this step. &nbsp;The physical pixels are mutated, but the “logical value” isn’t. &nbsp;The logical value is the result of a pure function “applyEditToPixels(oldPixels)” which is captured by the new step in the history. &nbsp;The mutation is tightly encapsulated as an implementation detail. &nbsp;</div><div><br class=""></div><div>I agree that we need to allow for implementation details like this. &nbsp;But we should find other ways when possible. &nbsp;And we should probably have to be explicitly clear about our intent if we want to implement a pure value which is hiding an implementation like this.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">The only other way I could think of is for each history step to use UUIDs to reference tile pixel buffers, and manage a separate map of [UUID: PixelBuffer]. Possibly this approach might have other benefits, but I think it doesn’t differ practically in ‘purity’ of state vs one state tree involving pointers. The purity is from the point of view of the programmer, where they know their system is purely additive.</div><div class=""><br class=""></div><div class="">The guarantee is in the system the programmer has created. Not allowing pointers to carefully managed mutable state is too rigid.</div></div></div></blockquote><div><br class=""></div><div>I am not suggesting they shouldn’t be allowed. &nbsp;I absolutely agree that they *should* be allowed! &nbsp;This is one reason why I love Swift! &nbsp;It blends functional and imperative in a very nice way.</div><div><br class=""></div><div>It seems likely that we will eventually have ownership semantics of some kind in Swift. &nbsp;When we have that we will have the ability to have unique references to mutable state. &nbsp;I have no problem viewing that as a pure value, because the mutation is local. &nbsp;It is really no different than a `var Int`, it is just indirect.</div><div><br class=""></div><div>However, if we share references to the mutable state then we are introducing potential for non-local mutation. &nbsp;I believe it is extremely useful to have *parts* of our program that don’t allow for this, and ideally get the compilers help with ensuring this.</div><div><br class=""></div><div>I hope that doesn’t seem like to rigid a request! &nbsp;I want *choice* not rigidity!</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 23 May 2016, at 5:12 AM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On May 22, 2016, at 12:04 PM, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Mon May 16 2016, Matthew Johnson &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On May 15, 2016, at 2:01 PM, Dave Abrahams<br class="">&lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:<br class=""><br class=""><br class="">on Fri May 13 2016, Matthew Johnson &lt;<a href="http://matthew-at-anandabits.com/" class="">matthew-AT-anandabits.com</a><br class="">&lt;<a href="http://matthew-at-anandabits.com/" class="">http://matthew-at-anandabits.com/</a>&gt;&gt; wrote:<br class=""><br class=""></blockquote><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Sent from my iPad<br class=""><br class=""><blockquote type="cite" class="">On May 13, 2016, at 9:12 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">on Mon May 09 2016, Matthew Johnson &lt;<a href="http://matthew-at-anandabits.com/" class="">matthew-AT-anandabits.com</a>&gt; wrote:<br class=""><br class="">My claim is that substituting the constraint of “it has value<br class="">semantics,” while presumably looser than the PureValue constraint, would<br class="">not compromise the correctness of your view controller, so not only is<br class="">the meaning of PureValue hard to define, but it doesn't buy you<br class="">anything. &nbsp;If you want to refute that, just show me the code.<br class=""><br class="">This is not an algorithmic use but is still perfectly valid IMO.<br class=""><br class="">If the properties of PureValue matter to your view controller, there's<br class="">an algorithm somewhere that depends on those properties for its<br class="">correctness.<br class=""><br class="">In many cases it may just be view configuration that depends on those<br class="">properties. &nbsp;I suppose you can call view configuration code an<br class="">algorithm but I think that would fall outside of common usage.<br class=""></blockquote>It's an algorithm, or if the configuration is declarative, there's<br class="">an algorithm that manipulates it. &nbsp;That said, I still don't have a<br class="">concrete example of how view configuration can depend on these<br class="">properties.<br class=""></blockquote>The algorithm might just be "copy x bit of data to y view<br class="">property, etc". &nbsp;That is so trivial that it feels like a stretch to<br class="">call it an algorithm.<br class=""></blockquote><br class="">Algorithms can be trivial.<br class=""></blockquote><br class="">Fair enough. &nbsp;Although in most contexts people don’t use the word when<br class="">discussing the trivial.<br class=""></blockquote><br class="">Yes, quite a shame, that.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">That "algorithm" doesn't depend on this property because it<br class="">executes at a single point in time. &nbsp;However, a view controller<br class="">might depend on that property in order to render properly across<br class="">time (for example, configuring cells as they scroll on and off<br class="">screen).<br class=""></blockquote>The example is too abstract for me to understand.<br class=""><br class="">Let me put this differently: I recognize that your concept of<br class="">“PureValue” may be a *sufficient* condition for some generic<br class="">algorithm/component to work, but it is never a *necessary*<br class="">condition, because genericity (or use of a superclass or protocol<br class="">type) erases details of the actual types involved from the point of<br class="">view of the algorithm/component. &nbsp;It doesn't matter if your type<br class="">contains a class reference if it has value semantic properties. &nbsp;My<br class="">claim is that PureValue is an overly-restrictive constraint that<br class="">makes many things less useful than they should be.<br class=""></blockquote><br class="">In many cases this is true - you don’t need more than value semantics<br class="">as you define it. &nbsp;However it is not at all true that PureValue is<br class="">never necessary for the correctness of code. &nbsp;I’m going to provide an<br class="">example to the contrary below.<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">This property allows us to separate values from non-local mutation<br class="">and make such separation a requirement. &nbsp;Rather than observing<br class="">mutations of objects with KVO, etc we might prefer to observe<br class="">something that provides a new aggregate value instead, while<br class="">requiring the entire aggregate value itself to be (observably)<br class="">immutable at all times (because we stored it with a let property<br class="">locally). &nbsp;This can make it easier to reason about correct behavior<br class="">of your code. &nbsp;But it doesn't work unless all visible parts of the<br class="">aggregate are immutable.<br class=""><br class="">If you're not familiar with Elm, Redux, etc it might be worth<br class="">taking a look.<br class=""></blockquote>That's a pretty broad link. &nbsp;At which parts do you think I should<br class="">look?<br class=""></blockquote><br class="">The piece that matters here is state management. &nbsp;The core concept is<br class="">to tightly control how mutations happen. &nbsp;It is modeled in terms of<br class="">state type T, an initial value t, an action type A (instances of which<br class="">are mutation commands, as in the command pattern), and a reducer<br class="">function (T, A) -&gt; T which produces a new state.<br class=""><br class="">Here’s a toy implementation that is somewhat simplistic but captures<br class="">the essence of the concept:<br class=""><br class="">class Store&lt;State, Action&gt; {<br class="">&nbsp;&nbsp;&nbsp;typealias Reducer = (State, Action) -&gt; State<br class=""><br class="">&nbsp;&nbsp;&nbsp;var stateHistory: [State]<br class="">&nbsp;&nbsp;&nbsp;let reducer: Reducer<br class=""><br class="">&nbsp;&nbsp;&nbsp;init(initialState: State, reducer: Reducer) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stateHistory = [initialState]<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.reducer = reducer<br class="">&nbsp;&nbsp;&nbsp;}<br class=""><br class="">&nbsp;&nbsp;&nbsp;func applyAction(action: Action) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let newState = reducer(stateHistory.last!, action)<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stateHistory.append(newState)<br class="">&nbsp;&nbsp;&nbsp;}<br class=""><br class="">&nbsp;&nbsp;&nbsp;var currentState: State {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return stateHistory.last!<br class="">&nbsp;&nbsp;&nbsp;}<br class=""><br class="">&nbsp;&nbsp;&nbsp;var canUndo: Bool {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return stateHistory.count &gt; 1<br class="">&nbsp;&nbsp;&nbsp;}<br class=""><br class="">&nbsp;&nbsp;&nbsp;func undo() {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if canUndo {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stateHistory.popLast()<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br class="">&nbsp;&nbsp;&nbsp;}<br class="">}<br class=""><br class="">This design relies on State being a PureValue. &nbsp;The whole idea is that<br class="">the only way any path of observation rooted at currentState can change<br class="">is when the reducer returns a new state when it is called by<br class="">`applyAction`. &nbsp;That guarantee<span class="Apple-converted-space">&nbsp;</span><br class=""></blockquote><br class="">I'm sorry, I can't understand what guarantee you're describing here.<br class="">Can you describe it in terms of preconditions, postconditions, and<br class="">invariants?<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I don’t think so. &nbsp;You could state precondition, postconditions, and invariants that would all rely on `==`. &nbsp;However, if reference semantic types implement `==` as `===` these would not be strong enough to provide the intended guarantee.</div><div class=""><br class=""></div><div class="">The guarantee depends on preventing *other code* from mutating values in `stateHistory`. &nbsp;If State is Array&lt;TypeWithMutableReferenceSemantics&gt; and some other code has a reference to the objects in the array the *other* code might mutate those objects. &nbsp;This would violate the semantic guarantee that is intended. &nbsp;But any preconditions, postconditions, and invariants stated using `==` would still be preserved because those shared mutable references still compare equal.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Just looking at the code, it seems to me that the only actual<br class="">requirement for sane results here is that the result (and effects) of<br class="">the `reducer` function depends only on the values of its arguments.<br class="">This is a highly precedented kind of requirement. &nbsp;For example, you<br class="">don't expect sort() to produce meaningful results if the comparison<br class="">function's result changes based on something other than the values of<br class="">the elements being compared.</div></div></blockquote><div class=""><br class=""></div><div class="">Yes, the reducer must be pure. &nbsp;But that is not enough for `Store` to behave as intended.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">cannot be provided by value semantics alone under your definition of<br class="">value semantics. &nbsp;Further, each state in the history is intended to be<br class="">a static snapshot of the “currentState” state at a specific point in<br class="">time. &nbsp;All states should be logically independent from each other and<br class="">from anything anywhere else in the program. &nbsp;This cannot be guaranteed<br class="">under your definition of value semantics.<br class=""></blockquote><br class="">That is exactly my definition of value semantics (modulo aggregation; a<br class="">value that is composed of other values obviously is dependent on the<br class="">values it's composed of). &nbsp;But distinct instances of types with value<br class="">semantics have values that are logically independent.</div></div></blockquote><div class=""><br class=""></div><div class="">The modulo aggregation thing is exactly what this whole thread hinges on. &nbsp;What I am saying is that sometimes it is important that the aggregate<span class="Apple-converted-space">&nbsp;</span><i class="">as a whole</i><span class="Apple-converted-space">&nbsp;</span>have value semantics. &nbsp;In other words, if any of it’s salient attributes are references the objects they point to must have value semantics (which requires immutability).</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">If we allow State to be Array&lt;MyMutableReferenceType&gt; which has value<br class="">semantics under your definition it is clear that we should have no<br class="">expectation that the desired properties are preserved. &nbsp;<br class="">The Store class is fundamentally broken if it can be used with State<br class="">types that are not pure values.<br class=""></blockquote><br class="">It depends on the semantic requirements placed on `reducer`. &nbsp;If you<br class="">insist that `reducer` should be able to do anything at all, then clearly<br class="">you need to constrain `State` in ways that make this component less<br class="">useful than it might otherwise be. &nbsp;But even then, you can't allow<br class="">`reducer` to *whatever* it wants because it could circle back and modify<br class="">the `Store` instance.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">`reducer` is intended to be pure. &nbsp;I didn’t specify that because Swift doesn’t have syntax for it. &nbsp;I was just giving valid Swift code and discussing the latent requirements of `State`.</div><div class=""><br class=""></div><div class="">Requiring `reducer` to be pure is not enough if we allow `State` to have salient mutable reference semantics attributes. &nbsp;The references contained in `initialState` and visible via `currentState` could be captured and mutated by any code working with the store.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">I’m not sure why it didn’t occur to me sooner, but this strategy for<br class="">managing app state is very similar in nature to what Sean Parent<br class="">discusses in his value semantics talk<br class="">(<a href="https://www.youtube.com/watch?v=_BpMYeUFXv8" class="">https://www.youtube.com/watch?v=_BpMYeUFXv8</a><br class="">&lt;<a href="https://www.youtube.com/watch?v=_BpMYeUFXv8" class="">https://www.youtube.com/watch?v=_BpMYeUFXv8</a>&gt; and related<br class=""><a href="https://www.youtube.com/watch?v=bIhUE5uUFOA" class="">https://www.youtube.com/watch?v=bIhUE5uUFOA</a><br class="">&lt;<a href="https://www.youtube.com/watch?v=bIhUE5uUFOA" class="">https://www.youtube.com/watch?v=bIhUE5uUFOA</a>&gt;).<br class=""><br class="">Sean discusses using value semantics to model applications state (he<br class="">calls it document). &nbsp;His examples don’t use reified actions and<br class="">reducer functions so it is a bit different but it relies on the same<br class="">pure value semantics. &nbsp;The demo he gives in the talk is a toy example<br class="">modeled on the design Photoshop uses to implement its history feature.<br class="">This design relies on each document in the history being an aggregate<br class="">which is a PureValue. &nbsp;This is not an academic discussion, but on with<br class="">real world practical utility.<br class=""></blockquote><br class="">I'm very familiar with this talk; it was a major inspiration for my<br class="">presentation at WWDC last year. &nbsp;I'll freely admit I get most of my good<br class="">ideas from Sean ;-)<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Great! &nbsp;I would be pretty surprised if Sean thinks the distinction I am trying to make is unimportant. &nbsp;His talk indicates that he is very concerned about shared mutable state. &nbsp;All I am looking for is a constraint that lets me say “the aggregate rooted at type Foo does not contain shared mutable state”.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">Sean says “value semantics is similar to functional programming,<br class="">except objects still have addresses and in-situ operations… You're<br class="">trying to maintain the ability to locally reason about your code but<br class="">you're not denying the fact that the machine has memory and you can do<br class="">in-situ operations on it”. &nbsp;<br class=""><br class="">Towards the end he quotes from a discussion he had with John Backus<br class="">(inventor of FP). &nbsp;John said: “it always annoyed me that FP and the no<br class="">side effect way of programming had become a religion. &nbsp;With FP I was<br class="">trying to come up with a mathematically rigorous way to program and I<br class="">understood the complexities of having side effects. &nbsp;I always knew we<br class="">had to deal with side effects, I just wanted a structured way to do<br class="">it.” &nbsp;John agreed that Sean’s approach to value semantics provides<br class="">such a structure. &nbsp;Allowing shared mutable references throws away that<br class="">structured approach. &nbsp;(As an aside, this is the most exciting thing<br class="">about value semantics IMO - it provides a structured approach to side<br class="">effects, allowing local reasoning about code).<br class=""><br class="">Sean gives an example of how references break the ability to reason<br class="">locally where he has two shared_ptrs that point to the same object:<br class=""><br class="">"If you look at it in terms of just the individual types you kind of<br class="">do have value semantics. &nbsp;When I copy a shared pointer it copies the<br class="">pointer with value semantic operations... &nbsp;The problem is the<br class="">references. &nbsp;When I'm looking at a shared_ptr I'm looking at it as if<br class="">I have the object. &nbsp;<br class=""></blockquote><br class="">This is the key phrase; it is about the implied programming model for<br class="">shared_ptr, which is a cultural phenomenon, not an absolute truth. &nbsp;</div></div></blockquote><div class=""><br class=""></div><div class="">I’m not quite sure I follow you here. &nbsp;Sean has a slide in the presentation which shows two shared_ptrs to the same object. &nbsp;He draws a boundary around the whole thing and calls that (both shared_ptrs *and* the object) the value. &nbsp;His point is that you cannot consider the shared_ptr on its own, or even one of the shared_ptrs and the object that is referenced. &nbsp;They are intricately inter-related.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">Yes,<br class="">when people get a reference to a class instance in Swift, they normally<br class="">don't even think about what's stored in the instance as being distinct<br class="">from the value of the reference, and indeed the language syntax is more<br class="">hostile to making that distinction than the syntax of C++. &nbsp;Defining the<br class="">value of a reference to be the address it points at (unless the instance<br class="">is immutable) allows everything to fall back into place, logically<br class="">speaking.<br class=""><br class="">Whether programmers can learn to understand the world this way is<br class="">certainly debatable, but it's pretty clear to me that leaving “the value<br class="">of a reference” undefined is untenable, and defining it in any way that<br class="">doesn't result in a reference having value semantics would make<br class="">describing algorithm semantics almost impossible. &nbsp;So what's the<br class="">alternative?<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I agree that this is the right approach when you are writing algorithms like `rotate`, etc. &nbsp;The reference is the value you’re concerned with.</div><div class=""><br class=""></div><div class="">I also think it is important to be able to make a distinction between an aggregate that is logically independent from any other data structures in your program and an aggregate which contains shared references to mutable state that is also referenced elsewhere in your program. &nbsp;In this case you are concerned with the state that is referenced (specifically, whether it the state is mutable and whether you have a reference that is guaranteed to always be unique - like unique_ptr or an owned reference in Rust - or not).</div><div class=""><br class=""></div><div class="">We need to be able to look at the world both ways. &nbsp;They are both very useful in different contexts.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">So really what I have is two objects that intersect. &nbsp;So really my<br class="">object in the program is this whole connected mess. &nbsp;At any particular<br class="">point in code I have difficulty reasoning about the whole thing. &nbsp;The<br class="">shared structure breaks our ability to reason locally about code."<br class=""><br class="">Sean makes an important distinction between looking at individual<br class="">types and looking at the aggregate as a whole. &nbsp;It is very important<br class="">to him that the entire aggregate be logically independent as this<br class="">facilitates local reasoning. &nbsp;This is exactly what I have been calling<br class="">a pure value. &nbsp;Pure value never allows any intersection to be observed<br class=""></blockquote><br class="">Yes, but: you can only measure an intersection of two values if *you<br class="">stay within the boundaries of those values*. &nbsp;</div></div></blockquote><div class=""><br class=""></div><div class="">If you consider a shared_ptr to define the boundary of its value then this is not what Sean said. &nbsp;In Sean’s talk he calls the object that two shared_ptrs reference the “intersection”. &nbsp;He crosses the reference when measuring intersection.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">A value type can contain a<br class="">reference to a shared cache as an incidental part, and this reference<br class="">can even be observable, as long as it is clearly distinguished as *not*<br class="">being within the boundaries of the value. &nbsp;One consequence of that is<br class="">that the results of equality comparison would never depend on the state<br class="">of the cache.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Agree. &nbsp;I’m not sure why you would expose the cache, but it is effectively the same as the capacity of an array. &nbsp;It is incidental and implementation related, not part of the salient semantics of the type.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">(immutable intersections are allowed because they cannot be observed,<br class="">which Sean alludes to in passing). &nbsp;Incidentally, it is pretty clear<br class="">from the talk that immutable intersection is heavily used in Photoshop<br class="">history in order to keep memory use reasonable. &nbsp;This falls into the<br class="">category of persistent data structures.<br class=""><br class="">My impression is that Sean’s definition of "value semantics” excludes<br class="">“intersecting objects” (where the intersection is mutable) and is<br class="">aligned with John’s “full value semantics” and the notion of “pure<br class="">value” we have been discussing.<br class=""></blockquote><br class="">I think I discussed this with Sean a week ago…</div></div></blockquote><div class=""><br class=""></div><div class="">And what was the outcome of that discussion? &nbsp;I would be very interested in hearing what he had to say.&nbsp;</div><div class=""><br class=""></div><div class="">Let’s consider the Photoshop history example since that ties back to something we know has proven to work very well in practice in a large scale application. &nbsp;</div><div class=""><br class=""></div><div class="">I’ll approximate based on what I could infer from Sean’s talk. &nbsp;Among other things, the document aggregate contains bitmap values. &nbsp;These are structured as a container of pointers to pixel buffers. &nbsp;The entire document aggregate is a persistent data structure that uses CoW to share as much memory as possible between snapshots. &nbsp;When a drawing operation is performed, relevant pixel buffers are copied and mutated by the operation and a new document snapshot is added to the history.</div><div class=""><br class=""></div><div class="">It is absolutely essential to this design that the pixel buffer pointers are not shared with code that can write to them. &nbsp;If this was allowed many snapshots would likely be affected and the history would be corrupted.</div><div class=""><br class=""></div><div class="">The `Store` example above is intended to preserve the same semantics as Photoshop does with its history feature. &nbsp;This depends on `State` being a pure value. &nbsp;If `State` is `Array&lt;MutableReferenceSemanticType&gt;` those semantics simply cannot be preserved. &nbsp;It is admittedly a toy example but I think it serves to demonstrate the point.</div><div class=""><br class=""></div><div class="">You could argue it is unnecessarily limiting to constrain `State` to be a pure value. &nbsp;I don’t think that’s a fair critique. &nbsp;In any practical scenario where you would use `State` you actually *want* this constraint and want as much help as possible in ensuring that your program adheres to it.</div><div class=""><br class=""></div><div class="">-Matthew</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">--<span class="Apple-converted-space">&nbsp;</span><br class="">-Dave<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>