Multiple dispatch in an inner method

I seem to need to use multiple dispatch in an inner constructor. I’ve never needed it before, nor can I find any information about it in the docs, thought I’d ask here. Is there any particular problem or aspect I need to keep in mind when doing that?

The reason for this is the following MWE (stripped of everything but the essential parts):

abstract type AbstractPeriod end

abstract type Instantaneous <: AbstractPeriod end

abstract type Prolonged <: AbstractPeriod end

struct Period{T <: AbstractPeriod}
    anchor
    duration

    Period(s) = new{Instantaneous}(s, 0)
    Period(s, d) = new{Prolonged}(s, d)
end

struct Temporal{T <: AbstractPeriod}
    time::Period{T}
    # more fields...
end

struct POIType{T <: AbstractPeriod}
    name
    # more fields...
end

struct POI{T <: AbstractPeriod}
    type::POIType{T}
    temporal::Temporal{T}
    # more fields...
end

The whole gist of this setup is that POI has two fields whose types are containers whose type is identical. I’m using an abstract type to accomplish this, AbstractPeriod, and Period is using that abstract type depending on its arguments… If any of you has some insight on how to improve on this I’d love to hear it.

I don’t think there is anything special going on here. That said, I wonder if you would be better off with two separate types for what seem to be two separate concepts.

Beware of the abstract field types though, but I am assuming that is just for the MWE.

OK, that’s great to hear.

I started off that way, but then I need to connect these two types in POI somehow. Still think about it.

Yea, it’s just for the MWE.

Thanks!

Here’s what I coalesced on, so far:

abstract type AbstractPeriod end

abstract type Instantaneous <: AbstractPeriod end

abstract type Prolonged <: AbstractPeriod end

abstract type POIType{T <: AbstractPeriod} end

for i in (:Nest, :Feeder)
    @eval struct $i <: POIType{Instantaneous} end
end

for i in (:Track, )
    @eval struct $i <: POIType{Prolonged} end
end

abstract type DurationType{T <: AbstractPeriod} end

struct Interval <: DurationType{Prolonged}
    anchor::Nanosecond
    duration::Nanosecond
end

struct Instant <: DurationType{Instantaneous}
    anchor::Nanosecond
end

struct POI{P <: POIType, D <: DurationType}
    type::P
    temporal::D
    POI(type::P, temporal::D) where {T <: AbstractPeriod, P <: POIType{T}, D <: DurationType{T}} = new{P, D}(type, temporal)
end