How to describe parametric Union Types and types in struct

Hi, I’m trying to define several types like:

using StaticArrays
struct CartesianPoint{T <: Number} <: FieldVector{3, T}
    x::T
    y::T
    z::T
end

struct UnitCartesianPoint{T <: Number} <: FieldVector{3, T}
    x::T
    y::T
    z::T
end

struct PolarPoint{T <: Number} <: FieldVector{3, T}
    r::T
    θ::T
    h::T
end

struct UnitPolarPoint{T <: Number} <: FieldVector{3, T}
    r::T
    θ::T
    h::T
end

const AbstractPoint{T} = Union{CartesianPoint{T}, PolarPoint{T}, UnitCartesianPoint{T}, UnitPolarPoint{T}} where T

struct LOR{T <: AbstractPoint}
    origin::T
    direction::T
end

struct Gamma{P<:AbstractPoint, T} 
    p::P{T}
    r::Array{T, 1}
end

I got

ERROR: LoadError: TypeError: in Type{...} expression, expected UnionAll, got TypeVar

The definition of Gamma is trying to define a composite of Point-like type and another array with same number type. UnitCartesianPoint and UnitPolarPoint are just points with norm restricted to one (although I don’t know how to restrict it in struct definition).

  1. Is this the proper way to describe this kind of types? Especially for const AbstractPoint, I don’t know if this is the correct way, it seems a little wired to me.

  2. How to solve the Error?

try

struct Gamma{T, P <: AbstractPoint{T}}
    ...

to enforce the type constraint.

A simpler solution could be making all the “point” types above <: AbstractPoint, and then define the latter as a subtype of FieldVector{3, T}. This would mean you (or some other module) could add new subtypes.