# Help with parametric definition (Unitful.jl)

**URL:** <https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610>\
**Category:** General Usage\
**Tags:** package, unitful\
**Created:** [April 1, 2019, 7:48pm UTC](https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610 "2019-04-01T19:48:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [April 1, 2019, 7:48pm UTC](https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610/1 "2019-04-01T19:48:33Z")

</div>

I need some help with the definition of a function, using the unitful package.  
i know that the units have the dimensions inside the type, and i need to access that information.  
uniful.jl provides the function dimension(T) and dimension(x::T), that gives the correct dimension information, so that:

```julia
dimension(u"L/mol") == dimension(123.0u"m^3/kmol)
true

```

i need some help defining a function that accepts a unitful type with specific dimensions, something like this:

```julia
using Unitful
function testdim(x::T) where dimension(T) == dimension(1.0u"L/mol") 
return 1
end

```

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [April 1, 2019, 7:56pm UTC](https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610/2 "2019-04-01T19:56:12Z")

</div>

a little more information, the value x is of type x::Unitful.Quantity{U,D}), so this simplifies the definition:

```julia
using Unitful
function testdim2(x::Unitful.Quantity{U,D}) where {U,D == dimension(u"K")}
return 1
end

```

this doesn’t work yet, but is close

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [April 1, 2019, 8:38pm UTC](https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610/3 "2019-04-01T20:38:46Z")

</div>

Do you look for something like this

```julia
f(x::Quantity{<:Number, Unitful.𝐋^3*Unitful.𝐍^-1}) = 1

```

or maybe

```julia
function testdim2(x::Unitful.Quantity{U,D}) where {U,D}
    return D == dimension(u"K")
end

```

?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [April 1, 2019, 9:01pm UTC](https://discourse.julialang.org/t/help-with-parametric-definition-unitful-jl/22610/4 "2019-04-01T21:01:58Z")

</div>

The first one seems like a solution to me! I don’t have a computer right now, but I will inform you about the results!
