# How to describe parametric Union Types and types in struct

**URL:** <https://discourse.julialang.org/t/how-to-describe-parametric-union-types-and-types-in-struct/15212>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 20, 2018, 4:54am UTC](https://discourse.julialang.org/t/how-to-describe-parametric-union-types-and-types-in-struct/15212 "2018-09-20T04:54:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiang0x48](https://avatars.discourse-cdn.com/v4/letter/x/53a042/32.png) [@xiang0x48](https://discourse.julialang.org/u/xiang0x48)\
**Post date:** [September 20, 2018, 4:54am UTC](https://discourse.julialang.org/t/how-to-describe-parametric-union-types-and-types-in-struct/15212/1 "2018-09-20T04:54:26Z")

</div>

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

```julia
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

```julia
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?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 20, 2018, 7:42am UTC](https://discourse.julialang.org/t/how-to-describe-parametric-union-types-and-types-in-struct/15212/2 "2018-09-20T07:42:40Z")

</div>

try

```julia
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.
