How to restrict type parameter to be subclass of a parameterized type

#         This part is the struct's where clause.
#         U written first because T<:Foo{U} depends on U
#         vvvvvvvvvvvvvv
struct Baz{U, T<:Foo{U}} <: Foo{U}
  baz :: U
end

where {T<:Foo{U}} where U is equivalent to where {U, T<:Foo{U}}, it’s just you need to write it like the latter because you can’t write where, let alone chains of them, in a struct definition’s where clause. You can write where in iterated union types annotating the fields, though.

1 Like