In addition to what others have said, you can mostly achieve what you’re looking for with an extra type parameter, but it is inconvenient:
struct MyStruct{L,P, N}
a::SVector{L,Other1}
b::SVector{P,Other2}
c::SVector{N,Float64}
function MyStruct{L, P, N}(...)
# Check that N == L + P here
....
end
end
# Convenient outer constructor that computes N for you
function MyStruct{L, P}(...) where {L, P}
MyStruct{L, P, L + P}(...)
end
I hope it is, I have been just implementing a bunch of stuff using that, without even thinking about it
But what I wanted to add is that the additional parameter is sort of ugly, but you can safely ignore it for dispatch, i. e., you can use something like
f(x::MyStruct{L,P}) where {L,P} = ...
ignoring the fact that there is a third parameter L+P, and that is supported. So, the combination of a convenient constructor with this pattern makes carrying the additional parameter not as cumbersome as it might seem.
(the SMatrix type has 4 parameters, the last one being sort of redundant, and there are several constructors that use that pattern to skip it in the API).
I hope so, but I couldn’t find anything in the manual about that. This is probably very common (and very useful), maybe it should be better documented?
I agree with Leandro, the implementation has some subtle bugs, there is no mention in the documentation, and very simple code that I would guess on working simply does not work.