You don't have to do this in the type definition, you can do it at
introspection time:
fieldtype(Foo{Float64,3},:a) returns Array{T,N}
fieldtype(Foo{Float64,3},:b) returns Array{Float64,3}
More generally:
julia> T, N = TypeVar(:T, true), TypeVar(:N, true)
(T,N)
julia> fieldtype(Foo{T,N}, :a).parameters[1].bound
false
julia> fieldtype(Foo{T,N}, :b).parameters[1].bound
true
You can inspect the pieces to see how this all works. (`dump` is your friend.)
Best,
--Tim
On Monday, September 19, 2016 6:36:15 PM CDT 'Greg Plowman' via julia-users
wrote:
> For a parameterised composite type, I want to distinguish between
> fields defined with parameters and generic fields.
>
> An example is probably best:
>
> type Foo{T,N}
> a::Array
> b::Array{T,N}
> end
>
> fieldtype(Foo,:a) returns Array{T,N}
> fieldtype(Foo,:b) returns Array{T,N}
>
>
>
> And if I use different parameters:
>
> type Bar{S,M}
> a::Array
> b::Array{S,M}
> end
>
> fieldtype(Bar,:a) returns Array{T,N}
> fieldtype(Bar,:b) returns Array{S,M}
>
>
> So if I'm careful to use different parameters to the default for the
> field type (Array in this case), I could perhaps distinguish between
> parameterised/non-parameterised fields.
>
> However, it would be nice if fieldtype returned no parameters for case
> where they are not specified for the field.
> i.e. fieldtype(Foo,:a) returns Array
>
> Are there any other suggestions?