Dynamic immutable type

Some workarounds:

  • introduce a wrapper type for matrix:
    mutable struct ReplaceableMatrix
        matrix::Matrix{Float64}
    end
    
    struct MyType
        some_field::SomeType
        matrix::ReplaceableMatrix
    end
    
  • make MyType mutable with all fields immutable, except for matrix:
    mutable struct MyType
        const some_field::SomeType
        matrix::ReplaceableMatrix
    end
    

It would be possible to add a resize! method for Array, however, as some have pointed out, the desired semantics of such a method would not be obvious (what should happen to the existing elements).

2 Likes