How does something like `let y: Time = 1 year` work? Does it take into consideration the idea of leap years and leap seconds, counting a single year as 365.2422 days[0]? Or does it count as 365 days?<p>I got curious and installed the CLI tool[1] and found that it does indeed account for leap second / leap years:<p>>>> let jahr: Time = 1 year<p>>>> let tage: Time = jahr -> days<p>>>> tage<p><pre><code> = 365.243 day [Time]
</code></pre>
References:<p>0: <a href="https://museum.seiko.co.jp/en/knowledge/story_01/" rel="nofollow noreferrer">https://museum.seiko.co.jp/en/knowledge/story_01/</a><p>1: <a href="https://numbat.dev/doc/cli-installation.html" rel="nofollow noreferrer">https://numbat.dev/doc/cli-installation.html</a>
How does Numbat infer the type/unit for operations that involve transcendental functions like the trigonometric functions and the natural logarithm? How about for exponents that are not integers (rational or irrational)?<p>I've seen from to time some empirical equations that result to this. Usually, it's just hand-waved away and the non-integer units are ignored or dropped when the transcendental function is evaluated. I guess the trivial answer is probably add an extra factor with a value of 1 with the reciprocal units to result to the said type 1 for dimensionless units?
the classic problem for such number systems is linear algebra <a href="https://yosefk.com/blog/can-your-static-type-system-handle-linear-algebra.html" rel="nofollow noreferrer">https://yosefk.com/blog/can-your-static-type-system-handle-l...</a><p>the issue is that each column and each row of a matrix can have different units. worse, gauss-jordan elimination chooses which rows to operate on dynamically. there is eventually a solution to this problem in c++ far down the comments thread<p>i don't see anything in <a href="https://numbat.dev/doc/type-system.html" rel="nofollow noreferrer">https://numbat.dev/doc/type-system.html</a> about aggregate types such as vectors, matrices, maps, arrays, lists, trees, records, etc., though it does have a suggestively named scalar type. i wonder how it handles this sort of thing
If I’m reading this correctly, the Frink language has similar features (and also seems darn useful!) <a href="https://frinklang.org/" rel="nofollow noreferrer">https://frinklang.org/</a>
Still reading the article, and really intrigued by and love this idea. But can I just say that I find this intro extremely well written. I feel like the writer is reading my thought process almost. Wvery time I start to form questions about decisions made in the language, it seems to answer them one or two paragraphs later. I feel like this is incredibly rare and yet incredibly important in an intro piece. Nicely done on the author['s]/[s'] part.
This is really cool!<p>If the author is around, I notice in the README you mention the GNU units program, which I use quite a bit. I'm curious if you've made any notable divergences from it?
Impressive!<p>One thing I find unintuitive is the implementation of variable length units (like months or years) as an averaged constant. Then again, perhaps that’s the point - and e.g. working with months without specifying a calendar is just unintuitive.
Can it be used as a date calculator? I didn't see a way to specify "today" or "tomorrow". Like "today" + 14 days etc.
Modeling compile-time units was one of the memes of c++ 11. One of many examples:<p><a href="https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/" rel="nofollow noreferrer">https://benjaminjurke.com/content/articles/2015/compile-time...</a>
> On the other hand, 3 months + 2 lightyears is ill-typed, because the right-hand side is of type Length. You can change ‘years’ to ‘lightyears’ in the example above to see the resulting compiler error.<p>Why not both? Make lightyears both Length and Time
I can't resist mentioning F# Units of Measure aka UoM :)<p><a href="https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...</a>
Super cool! I love when programming languages try to do more with types.<p>Julia has a neat little library called Unitful.jl[1] which does almost exactly what Numbat does by taking advantage of Julia's extremely flexible type system. Extending it to cover all of Numbat's functionality could be trivially accomplished in a few lines. In fact, fun type magic like this is pretty much my primary motivation for using Julia in the first place.<p>Not that I want to detract from the author's hard work, of course, I'm just very excited about Julia! Numbat is obviously an awesome project, and I can't wait to see where it leads!<p>[1] <a href="https://painterqubits.github.io/Unitful.jl/stable/" rel="nofollow noreferrer">https://painterqubits.github.io/Unitful.jl/stable/</a>
Or you could just use Nim [0], where this sort of thing can be implemented in Nim's macro system. Then you have a regular programming language combined with CT safe units. :)<p>It even pretty much looks identical to those Numbat snippets!<p><pre><code> import unchained
let earth_mass = 5.972168e24.kg
let solar_mass = 1.9885e30.kg
let lunar_mass = 7.342e22.kg
let distance_sun = 1.AU # astronomical unit
let distance_moon = 384_400.km
let force_sun = G_Newton * earth_mass * solar_mass / distance_sun
let force_moon = G_Newton * earth_mass * lunar_mass / distance_moon
echo force_sun / force_moon
# 69593.6 UnitLess
</code></pre>
Sorry for the shameless plug. ;) Numbat looks quite cool though and the article talks about a lot of things to think about when writing such a program / lib / programming language.<p>[0]: <a href="https://github.com/SciNim/Unchained">https://github.com/SciNim/Unchained</a>
Frink (<a href="https://frinklang.org/" rel="nofollow noreferrer">https://frinklang.org/</a>) is an older language with similar design goals.<p>Frink runs on the JVM and is also available on Android.<p>I use it as a general purpose calculator on my smartphone.<p>It's really nice that Numbat is written in Rust :) Will have to try it out.
Remind me of GNU Units <a href="https://www.gnu.org/software/units/" rel="nofollow noreferrer">https://www.gnu.org/software/units/</a>
Ada’s type system also allows compile-time checking of units like physical dimensions:<p><a href="https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gnat_ugn_unw/Performing-Dimensionality-Analysis-in-GNAT.html" rel="nofollow noreferrer">https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gnat_ugn_unw/Perfor...</a><p><a href="https://blog.adacore.com/uploads/dc.pdf" rel="nofollow noreferrer">https://blog.adacore.com/uploads/dc.pdf</a>
<i>perform computations with physical units.</i><p>It has units awareness --- not necessarily only <i>physical</i> units.<p>For example; light, temperature and time are measured in units but they are not <i>physical</i> units --- aka 3 dimensional.