Complicated type question

I’d like to define some types similar to the following simplified types. However, since T3’s type is determined by U, I’d rather not have to specify T when writing its type. Is there a way to do this?

abstract type T1{T}; end

mutable struct T2{T} <: T1{T}; x::T; end

mutable struct T3{T, U <: T1{T}} <: T1{T}; x::U; end

The motivation is that I need nested compositions of types such as T3{T,T3{T,T2{T}}} and don’t want to keep repeating T.

I am not sure I understand what you are trying to do.

In any case, I would advise against trying to express complex type relations in parameter restrictions. You can always have an inner constructor verify them.

3 Likes