How can I express the abstract type of a multi-parameter type that only matches the second parameter

If I have a type VS_Data{DIM,NDF} and a instance a::VS_Data{3,2}. Then we have isa(a,VS_Data{3})=true but isa(a,VS_Data{2})=false, which implies that VS_Data{DIM,NDF}<:VS_Data{DIM}. My question is how can I express the abstract type that only matches the parameter NDF?

As you discovered, supplying type parameters generally works from left to right.

To work around that, the general syntax applied to your example is

VS_Data{DIM,2} where DIM
1 Like

That’s what I want. Thanks a lot!

I wonder if it would be possible to support “currying” of underscores in situations like this:

VS_Data{_, 2}

There has been a long discussion on supporting this for function arguments (e.g. f(_, x)), and this would be a nice parallel to that. But perhaps the same problems show up here, like where the scope of _ should end?

2 Likes

Would it be possible to write a MWE to make it less abstract?

Although this is not really more ergonomic in this simple example, for more complex cases it can be convenient to define an alias with type parameters swapped (or generally, re-ordered) like:

const VS_DATA_swapped{NDF,DIM} = VS_Data{DIM,NDF} where {DIM,NDF}

Edit: for actual usecases const is probably a good idea.