Thank you @fengyang.wang, I find this approach adopted in Base a little complicated because after all we have a container of Foo
, and not a container of Foo
and T
.
I tried refactoring the code a la C++ as follows:
# concepts
abstract AbstractFoo{N,T}
dimension{N,T}(::AbstractFoo{N,T}) = N
coordtype{N,T}(::AbstractFoo{N,T}) = T
abstract AbstractContainer{F}
# partial specialization where we fix T = Float64
immutable Foo{N} <: AbstractFoo{N,Float64} end
# a container of AbstractFoo{N,T} where we save state in a vector of T
immutable Container{F<:AbstractFoo} <: AbstractContainer{F}
state::Vector{coordtype(F)}
end
but it returns the error:
ERROR: MethodError: no method matching coordtype(::TypeVar)
There is any workaround for this error? What is a better approach? I believe this is a very common issue that could also be part of a FAQ somewhere.