I would like to have the functionality displayed in the definition of S₂. This code obviously does not work (and I understand why), but what would be the closest thing to accomplishing such functionality? Thanks!
Background: I (will) have a lot of related types that have a lot in common, each with many fields with varying types. It is much easier (to me!), less maintenance, and less remembering to have a single parametric type than to define many individual ones and use subtyping. I can cut down on the maintenance part by generating various types programmatically, but that is not great for legibility. Alternatively, I can do something like struct S{T1,T2,T3,T4,T5}
, but that’s not great either. And yes, I do want parametric types.
(I suspect I’m setting myself up for a hard no, but would appreciate any suggestions and ideas.)
struct S₁{T₁, T₂}
x :: T₁
y :: T₂
end
struct T
end
struct X
end
const D = Dict( T => ( Int, Float64 ), X => (String, Int ) )
struct S₂{Q}
x :: D[Q][1]
y :: D[Q][2]
end
x = S₂{T}( 0, 1.0 )
# I want S₂{T} to give me the same as S₁{Int, Float64}