Dispatch on physical quantity or creating distinct types that behave like a float

Yeah, I missed the g in the 2nd formula, thanks for pointing out, I corrected it. And you are right about the units of course. Velocity was only an example, in reality I need electric field, chemical potential, particle density etc.

I had a look at Unitful.jl in the past and thought it only deals with units. But as you suggested it and showed the example using dimensions I looked again. Derived dimensions look good, but there’s still one catch. You can’t have two types with the same dimension, so you can’t do

@derived_dimension Area Unitful.𝐋^2
@derived_dimension AnotherArea Unitful.𝐋^2

Well, you can do that but can’t distinguish the two in dispatch. I only slightly understand how Unitful.jl works, but it seems logical to me this can’t work as the created type is basically defined by the dimension. My idea was to write methods for calculations and make it clear by type annotation what kind of physical property they take as arguments. This should avoid errors, in particular when combined with unit checking.

I found another thread here on this forum about a very similar question. AbstractNumbers.jl is suggested and seems exactly what I’m looking for. I guess combined with Unitful.jl it will do everything I want.

1 Like