I am a little confused about constructing composite types. Given the 
definition

type MyType
x::Int
y::Int = 6
MyType() = new()
end

an instance of MyType can be created using

m = MyType()

At that point, m.x acts as expected --- I can assign to it, read its value, 
and so forth. However, attempting to access m.y produces an error that 
MyType has no field y. Based on another post, I gather that my attempt to 
provide a value to m.y in this manner is not allowed If that's the case, 
what exactly is the effect of "y::Int = 6" If this part of the code is 
completely ignored, it would be really nice if the system let me know since 
initializing fields in this way is common in many languages.

Also, I gather that a workaround is to use a constructor that takes named 
arguments. Is that still the recommended way? With just two fields, things 
are not difficult, but if the type has 20, calling a constructor with 20 
positional arguments would be difficult.


Reply via email to