For many scientific computations, that would be really nice. For an inconvenient version, there are class libraries: I know one for Python, and I remember seeing one for C++ decades ago, when I was still a professional physicist. The problem here is that without language (compiler or parser) support for literals with units, the syntax gets awful. Here is what code should look like:Interesting language. lang/numbat.
Not sure how actually usable it is (as I'm not yet actually studied it), but it seems to be kinda "safe" language. It seems to free us from mangling units like km vs mile, kg vs lb, deg vs rad.
Unrelated with this thread? No, no! It's written in Rust (unfortunately for me to understand the implementation).
Code:
d = 3m # I'm omitting the type declaration for a didactic example
x = 12mm
t = 2s
v = d / t # The units of v should now be 1.5 m/s
r = d / x # The result should be 25 with no units
rrr = d + t # This should assert
Code:
d = Quantity(3, "m")
x = Quantity(12, "mm")
t = Quantity(2, "s")
Quantity v = d / t # The result will be Quantity(1.5, "m/s")
r = d / x # Is the type of r an int, a float, or Quantity(25, "") ?
Sadly, the number of people who really need this is small, so it's probably not worth it to add support to one of the major languages.
Footnote: That means "the parser would not be able to process ..."