f{T<:AbstractInnerType}(x::AbstractOuterType{T}) = <do something with T>However I would be very careful attaching a parameter N to the number of columns of an array. Unless you are sure you'll only have a small handful of unique values, you risk creating tons and tons of different types, all requiring specialized compilation of every function they touch. On Thu, Sep 17, 2015 at 2:10 PM, Spencer Russell <[email protected]> wrote: > I think my question boils down to: "How do I define a method catches any > subtype of a parametric supertype, but access the unparameterized part of > the subtype within the function body?" > > Say I have this type: > > abstract AbstractFoo{N, T} <: AbstractArray{T, 2} > > type Foo1{N, T} <: AbstractFoo{N, T} > data::Array{T, 2} > end > > Foo1{T}(arr::AbstractArray{T, 2}) = Foo1{size(arr, 2), T}(arr) > > So the Foo1 outer constructor sets the type parameter N based on the > number of columns of the contained array. > > When indexed by a Range, I want the returned value to be wrapped in a Foo1 > type, but it might be parameterized with a different value for N, but I > can't figure out the right type definition. The plan is to catch types that > are a subtype of Foo, but call the outer constructor to build the result > value. > > I've tried: > > Base.getindex{BT{N, T} <: AbstractFoo{N, T}}(foo::BT, I...) = > BT(foo.data[I...]) > > but apparently that has a malformed type parameter list. > > I've also tried > > Base.getindex{BT <: AbstractFoo}(foo::BT, I::Idx...) = BT(foo.data[I...]) > > But that doesn't get called because Foo1{N, T} is not a subtype of > AbstractFoo. > > What does work is defining > > Base.getindex(foo::Foo1, I::Idx...) = Foo1(foo.data[I...]) > > But then I have to define the getindex method for each concrete subtype > of AbstractFoo. > > Thanks for any help. It's possible that these gymnastics are a sign that I > just shouldn't parameterize on N and do any necessary checks at runtime, > but it feels like I'm close on this one. > > -s >
