# Unitful.jl: type matching dimensions

**URL:** <https://discourse.julialang.org/t/unitful-jl-type-matching-dimensions/114676>\
**Category:** General Usage\
**Created:** [May 24, 2024, 1:24pm UTC](https://discourse.julialang.org/t/unitful-jl-type-matching-dimensions/114676 "2024-05-24T13:24:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joh11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joh11/32/23140_2.png) [@Joh11](https://discourse.julialang.org/u/Joh11)\
**Post date:** [May 24, 2024, 1:24pm UTC](https://discourse.julialang.org/t/unitful-jl-type-matching-dimensions/114676/1 "2024-05-24T13:24:41Z")

</div>

Hi,

Up until now, I have only used Unitful for basic conversion, however I would like now to use it for type checking. However, I cannot make it work.

I want ensure (with type safety) that a given variable is an array of a specific dimension (energy here).

Here is the code:

```julia
energies = zeros(3, 3)u"eV"

const EnergyQuantity = Quantity{T, dimension(u"eV"), U} where T where U

# prints true, as expected
@show 3u"eV" isa EnergyQuantity
@show 3u"J" isa EnergyQuantity

# prints true, as expected as well
@show energies isa Array{T, 2} where T

# prints false !
@show energies isa Array{EnergyQuantity, 2}

```

I do not understand why the last line does not work. Is it due to limitations of the type system, or am I just not understanding how this work ?

Thanks !

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [May 24, 2024, 1:29pm UTC](https://discourse.julialang.org/t/unitful-jl-type-matching-dimensions/114676/2 "2024-05-24T13:29:42Z")

</div>

This is not specific to Unitful: [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/#man-parametric-composite-types)

> This last point is _very_ important: even though `Float64 <: Real` we **DO NOT** have `Point{Float64} <: Point{Real}`.

```julia
!(energies isa Array{ EnergyQuantity, 2})
# but
  energies isa Array{<:EnergyQuantity, 2}

```

---

<div class="post-metadata">

**Author:** ![Joh11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joh11/32/23140_2.png) [@Joh11](https://discourse.julialang.org/u/Joh11)\
**Post date:** [May 24, 2024, 1:51pm UTC](https://discourse.julialang.org/t/unitful-jl-type-matching-dimensions/114676/3 "2024-05-24T13:51:59Z")

</div>

Thanks ! I had the feeling I did not really understand this section of the documentation.

Now I understand more, it is because `EnergyQuantity` is not the exact base type of `energies`, so we need to use the subtype operator `<:` to resolve it.

Thanks again !
