title: Julia: How much can we change the objects in immutable struct type?
body: <p>I have an immutable structure with four objects defined as follows:</p>
  
  <pre><code>struct FltFric
      muS::Array{Float64, 2}
      muD::Array{Float64, 2}
      Dc::Float64
      W::Array{Float64, 2}
  end
  
  muS = repmat([0.6], 100, 1) # Coefficient of static friction
  muD = repmat([0.5], 100, 1) # Coefficient of dynamic friction
  Dc = 0.1                     # Critical slip distance
  
  FltFriction = FltFric(muS, muD, Dc, zeros(size(muS)))
  </code></pre>
  
  <p>I am modifying the values of <code>FltFric.muS</code> as follows:</p>
  
  <pre><code>FltFriction.muS[1:20] = 100
  </code></pre>
  
  <p>This works fine. But when I try to modify the value of W</p>
  
  <pre><code>FltFriction.W = (FltFriction.muS - FltFriction.muD)./(FltFriction.Dc)
  </code></pre>
  
  <p>This gives me an error: <code>type FltFric is immutable</code>. </p>
  
  <p>Why does the first statement not give error while the second one does? If the type is immutable, both statements should give an error. What is the difference between the two assignments?</p>
  
  <p>I know that I can circumvent the problem by typing <code>mutable struct</code>, but I don't understand the difference in my two assignments.</p>