TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Numbat – A programming language with physical dimensions as types

146 pointsby sharkdpover 1 year ago

26 comments

manifoldgeoover 1 year ago
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 &#x2F; leap years:<p>&gt;&gt;&gt; let jahr: Time = 1 year<p>&gt;&gt;&gt; let tage: Time = jahr -&gt; days<p>&gt;&gt;&gt; tage<p><pre><code> = 365.243 day [Time] </code></pre> References:<p>0: <a href="https:&#x2F;&#x2F;museum.seiko.co.jp&#x2F;en&#x2F;knowledge&#x2F;story_01&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;museum.seiko.co.jp&#x2F;en&#x2F;knowledge&#x2F;story_01&#x2F;</a><p>1: <a href="https:&#x2F;&#x2F;numbat.dev&#x2F;doc&#x2F;cli-installation.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;numbat.dev&#x2F;doc&#x2F;cli-installation.html</a>
评论 #38293186 未加载
评论 #38296093 未加载
评论 #38293968 未加载
jskhermanover 1 year ago
How does Numbat infer the type&#x2F;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&#x27;ve seen from to time some empirical equations that result to this. Usually, it&#x27;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?
评论 #38291996 未加载
kragenover 1 year ago
the classic problem for such number systems is linear algebra <a href="https:&#x2F;&#x2F;yosefk.com&#x2F;blog&#x2F;can-your-static-type-system-handle-linear-algebra.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;yosefk.com&#x2F;blog&#x2F;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&#x27;t see anything in <a href="https:&#x2F;&#x2F;numbat.dev&#x2F;doc&#x2F;type-system.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;numbat.dev&#x2F;doc&#x2F;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
评论 #38294397 未加载
评论 #38294621 未加载
joeatworkover 1 year ago
If I’m reading this correctly, the Frink language has similar features (and also seems darn useful!) <a href="https:&#x2F;&#x2F;frinklang.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;frinklang.org&#x2F;</a>
评论 #38294195 未加载
wwalexanderover 1 year ago
A month cannot be unambiguously represented as a length of time, as the length of a month is variable.
评论 #38291874 未加载
SuperNinKenDoover 1 year ago
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[&#x27;s]&#x2F;[s&#x27;] part.
exp1orerover 1 year ago
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&#x27;m curious if you&#x27;ve made any notable divergences from it?
评论 #38294550 未加载
nutateover 1 year ago
First project I&#x27;ve ever seen that made me instantly sponsor it. Then to only find out you wrote fd and hexyl and some other classics. Great work.
enbuggerover 1 year ago
In theory it can help to compute how many ore belts I need for producing full belt of white sciences in Factorio?
merelysoundsover 1 year ago
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.
评论 #38297772 未加载
indentitover 1 year ago
Can it be used as a date calculator? I didn&#x27;t see a way to specify &quot;today&quot; or &quot;tomorrow&quot;. Like &quot;today&quot; + 14 days etc.
评论 #38294165 未加载
评论 #38292894 未加载
benhurmarcelover 1 year ago
Apparently this replaces <a href="https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;insect">https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;insect</a>
评论 #38296242 未加载
praveen9920over 1 year ago
It’s interesting that they support currency units. Wonder how the conversion works. Probably have to provide conversion factor as well?
评论 #38293936 未加载
mlhpdxover 1 year ago
Modeling compile-time units was one of the memes of c++ 11. One of many examples:<p><a href="https:&#x2F;&#x2F;benjaminjurke.com&#x2F;content&#x2F;articles&#x2F;2015&#x2F;compile-time-numerical-unit-dimension-checking&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;benjaminjurke.com&#x2F;content&#x2F;articles&#x2F;2015&#x2F;compile-time...</a>
runamuckover 1 year ago
So if I try to get the Falcon to do the Kessel run in two Parsecs, Numbat will raise an exception.
评论 #38291870 未加载
Asposover 1 year ago
This is great. I want this as an addon to JS and Python.
评论 #38291989 未加载
eviksover 1 year ago
Cool that you can use actual 1 × 2 multiplication sign or 4 ⋅ 8 instead of that kludge of an asterisk *
youssefabdelmover 1 year ago
&gt; 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
评论 #38293818 未加载
evntdrvnover 1 year ago
I can&#x27;t resist mentioning F# Units of Measure aka UoM :)<p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fsharp&#x2F;language-reference&#x2F;units-of-measure" rel="nofollow noreferrer">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fsharp&#x2F;language-ref...</a>
评论 #38294350 未加载
评论 #38293532 未加载
评论 #38291767 未加载
评论 #38291409 未加载
评论 #38292372 未加载
cosmojgover 1 year ago
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&#x27;s extremely flexible type system. Extending it to cover all of Numbat&#x27;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&#x27;s hard work, of course, I&#x27;m just very excited about Julia! Numbat is obviously an awesome project, and I can&#x27;t wait to see where it leads!<p>[1] <a href="https:&#x2F;&#x2F;painterqubits.github.io&#x2F;Unitful.jl&#x2F;stable&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;painterqubits.github.io&#x2F;Unitful.jl&#x2F;stable&#x2F;</a>
评论 #38294823 未加载
评论 #38293174 未加载
V1ndaarover 1 year ago
Or you could just use Nim [0], where this sort of thing can be implemented in Nim&#x27;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 &#x2F; distance_sun let force_moon = G_Newton * earth_mass * lunar_mass &#x2F; distance_moon echo force_sun &#x2F; 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 &#x2F; lib &#x2F; programming language.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;SciNim&#x2F;Unchained">https:&#x2F;&#x2F;github.com&#x2F;SciNim&#x2F;Unchained</a>
评论 #38293782 未加载
评论 #38300503 未加载
评论 #38294855 未加载
评论 #38292345 未加载
thesuperbigfrogover 1 year ago
Frink (<a href="https:&#x2F;&#x2F;frinklang.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;frinklang.org&#x2F;</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&#x27;s really nice that Numbat is written in Rust :) Will have to try it out.
评论 #38293701 未加载
评论 #38294889 未加载
评论 #38293814 未加载
hsfzxjyover 1 year ago
Remind me of GNU Units <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;units&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;units&#x2F;</a>
评论 #38293169 未加载
docandrewover 1 year ago
Ada’s type system also allows compile-time checking of units like physical dimensions:<p><a href="https:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;gcc-4.9.4&#x2F;gnat_ugn_unw&#x2F;Performing-Dimensionality-Analysis-in-GNAT.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;gcc-4.9.4&#x2F;gnat_ugn_unw&#x2F;Perfor...</a><p><a href="https:&#x2F;&#x2F;blog.adacore.com&#x2F;uploads&#x2F;dc.pdf" rel="nofollow noreferrer">https:&#x2F;&#x2F;blog.adacore.com&#x2F;uploads&#x2F;dc.pdf</a>
评论 #38293161 未加载
pifover 1 year ago
You don&#x27;t need a new programming language for something that C++ templates with integer constants give you for free.
评论 #38293363 未加载
评论 #38291566 未加载
评论 #38294465 未加载
评论 #38292388 未加载
jqpabc123over 1 year ago
<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.
评论 #38288894 未加载