Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Thank you. I'm actually familiar with the book, the data structure described here, and finger trees (which is how Data.Sequence is implemented). I've implemented these data structures myself. Commented Oct 7, 2012 at 8:02
  • There's a useful subset of internally-mutable externally-mutable classes in which the internal representation of the object may change, but where none of the changes, singly or in any combination, affect the visible state of the object. For example, Java's strings have a cached hash-code field. Every string has a fixed hash code value, the cached field will always either be zero or that value, and the observable state of the string is the same in either case (beyond the fact that if the value is not faster, requests for the hash code can be processed faster). Commented Oct 8, 2012 at 23:26
  • Classes of that particular kind do not require any sort of inter-thread synchronization for correctness (though in some rare cases adding synchronization may improve efficiency by eliminating redundant work). Commented Oct 8, 2012 at 23:27
  • @supercat I see. But I'm not sure about not requiring synchronization. In the case of hashCode it's likely that saving hashCode to a variable is an atomic operation. But if it were stored in two variables, for example, or in a variable whose update isn't an atomic CPU operation, another thread could read and observe its value in an inconsistent state when only one part of the value is stored and the other still contains zero bits. I cannot imagine how this could be done without synchronization. Commented Oct 9, 2012 at 6:26