Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is immutable?</p> <p>Checking to see if the object only contains <code>val</code> fields is an overapproximation of immutability - the object may very well contain <code>var</code>s, but never assign different values in them. Or the segments of the program assigning values to <code>var</code>s may be unreachable.</p> <p>According to the terminology of <a href="http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf" rel="noreferrer">Chris Okasaki</a>, there are immutable data structures and functional data structures.</p> <p><strong>An immutable data structure</strong> (or a class) is a data structure which, once constructed in memory, never changes its components and values - an example of this is a Scala tuple.</p> <p>However, if you define the immutability of an object as the immutability of itself and all the objects reachable through references from the object, then a tuple may not be immutable - it depends on what you later instantiate it with. Sometimes there is not enough information about the program available at compile time to decide if a given data structure is immutable in the sense of containing only <code>val</code>s. And the information is missing due to polymorphism, whether parametric, subtyping or ad-hoc (type classes).</p> <p>This is the first problem with deciding immutability - lack of static information.</p> <p><strong>A functional data structure</strong> is a data structure on which you can do operations whose outputs depend solely on the inputs for a given state. An example of such a data structure is a search tree which caches the last item looked up by storing it in a mutable field. Even though every lookup will write the last item searched into the mutable field, so that if the item is looked up again the search doesn't have to be repeated, the outputs of the lookup operation for such a data structure always remain the same given that nobody inserts new items into it. Another example of a functional data structure are <a href="http://en.wikipedia.org/wiki/Splay_tree" rel="noreferrer">splay trees</a>.</p> <p>In a general imperative programming model, to check if an operation is pure, that is - do the outputs depend solely on inputs, is <a href="http://en.wikipedia.org/wiki/Undecidable_problem" rel="noreferrer">undecidable</a>. Again, one could use a technique such as abstract interpretation to provide a conservative answer, but this is not an exact answer to the question of purity.</p> <p>This is the second problem with deciding if something having <code>var</code>s is immutable or functional (observably immutable) - undecidability.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload