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.