Incomplete initialization (control which fields are initialized in `new`)

Regardless of the proposal to extend new this way (cf this comment), I still think that you are fighting the language on this. I would do something like

struct ClosedEndPoint{T}
    x::T
end

struct OpenEndPoint{T}
    x::T
end

struct UnboundedEndPoint end

const EndPoint{T} = Union{ClosedEndPoint{T},OpenEndPoint{T},
                          UnboundedEndPoint}

struct Interval{T}
    left::EndPoint{T}
    right::EndPoint{T}
    # constructor omitted
end

and let the compiler take care of keeping track of the flags via tha Union optimization. I don’t think it will be worse than manually keeping track of the flags with Symbol, and may be better. YMMV.

5 Likes