I am working with a family of models, which have certain properties, lets call them statenames and obsnames. Many of these are shared between models, so it would be nice to reuse them. Models are mapped to types in my code. I would like to query these properties for the types.
So I thought I would use abstract types like this:
abstract AbstractModel{S,O}
abstract FiveStateModel
statenames(::Type{FiveStateModel}) = (:NL,:NM,:NH,:EM,:EH)
abstract ObservedEUH
obsnames(::Type{ObservedEUH}) = (:E,:U,:H)
immutable SimpleModel1{T <: Real} <: AbstractModel{FiveStateModel, ObservedEUH}
x::T
y::T
end
Now I want
statenames(SimpleModel1)
to return (:NL,:NM,:NH,:EM,:EH). If types were covariant, I could use
statenames{S,O}(::Type{AbstractModel{S,O}}) = statenames(S)
obsnames{S,O}(::Type{AbstractModel{S,O}}) = obsnames(O)
but since they are not, I am using
statenames{S,O}(::AbstractModel{S,O}) = statenames(S)
obsnames{S,O}(::AbstractModel{S,O}) = obsnames(O)
and have to instantiate a SimpleModel1, eg
statenames(SimpleModel1(1.0,1.0))
Is there a workaround that would allow me to solve this in type-space?