Assigning default values to fields of a composite type is not yet supported.
Your inner constructor is also a little un-Julian, since `MyType() = new()` doesn’t assign any values to those fields. — John On Dec 21, 2013, at 4:37 AM, Marcus Urban <[email protected]> wrote: > 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. > >
