Parametric type with numbers

Hello!

I am having difficulties trying to model the adequate code for what I want to achieve.
Imagine I have the following struct:

struct Device
    a::NTuple{3,Float64}
    b::NTuple{2,Float64}
end

where b is always going to be one element shorter than a. How can I generalize this for N?

I figured that it would be something like

struct Device{N}
    a::NTuple{N,Float64}
    b::NTuple{N-1,Float64}
end

but it errors because I cannot perform substraction on types.

Thanks!

I think Matt’s answer here is still right:

5 Likes

There is GitHub - vtjnash/ComputedFieldTypes.jl: Build types in Julia where some fields have computed types which helps with this. There is also a github issue around this Proposal: Defer calculation of field types until type parameters are known · Issue #18466 · JuliaLang/julia · GitHub

1 Like

Thank you both!!

1 Like