Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

immutable vs struct and type vs mutable struct in Julia

Let's define 4 different classes of points:

type PointType
    x
    y
end

mutable struct PointMut
    x
    y
end

immutable PointImmut
    x
    y
end

struct PointStruct
    x
    y
end

What is the difference between PointType and PointMut? Why would someone choose one over the other?

Also what is the difference between PointImmut and PointStruct?

I tend to believe that they are just synonyms, but I didn't find this stated explicitly, so I wonder if there is a subtle difference hidden somewhere.

like image 839
tst Avatar asked Oct 21 '17 12:10

tst


1 Answers

type and immutable are valid up to julia 0.6, mutable struct and struct are the names of the same objects in julia 0.6 and forward. mutablein mutable struct means that the fields can change - which is actually fairly rarely used so being immutable is the default. mutable struct's are slower than structs.

like image 152
Michael K. Borregaard Avatar answered Oct 25 '22 22:10

Michael K. Borregaard