I’m just learning Julia, and I’m finding the docs not so clear on the differences between type and struct. In the docs there are no real examples of declaring custom types using the type keyword, instead there’s a section on composite types using struct. So I’m just pointing out that as a beginner the docs are leaving me with questions:
What is the difference between using struct and type, or mutable struct and type?
Why would you choose one over the other? Why is struct used in the docs rathe than type?
I will not comment on the aesthetic part (I happen to like struct), but note that “type” is used in another, very specific sense by Julia (the thing that dispatch operates on, etc), so using it for composite types was just confusing.
Sorry, I’m just a beginner. IIUC, the concept of type is not deprecated; it is only that the users shouldn’t define any type and they should use struct instead?
No, when the docs are talking about the concept of a type, then it doesn’t change (and this was a big part of why the change was necessary, the confusion when talking about a specific kind of type, i.e. a structure that might be mutable or immutable, vs. abstract types, primitive types, etc., or talking about the concept).
In your code (but not in any doc strings discussing the concept ), yes, replace immutable => struct, and type => mutable struct.
OK, I see your point, that is a bit unclear.
I believe, when it says “all objects are instances of”, simply means that the release isa Any is always for any object. (isa being true for instances of a particular type or subtype of the given type), so not really contradictory.
So, 1 is an instance of an Int, and it’s an instance of a Signed type, an Integer type, a Number type, and Any.
Thanks! I kind of understand what you mean. So probably the second sentence can be rephrased as the following?
When no supertype is given, the default supertype is Any – a predefined abstract type that all objects are instances of the concrete subtypes of and all types are subtypes of.
I’m not the best on documentation, one of the core people might be better at a good description.
You might want to bring it up on slack, or make a PR to change that in the documentation.