Live data from Hacker News

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

numbat.dev

51–60 of 122 posts

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

#51
> 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.

Why not both? Make lightyears both Length and Time

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

#52

Frink ( https://frinklang.org/ ) is an older language with similar design goals. Frink runs on the JVM and is also available on Android. I use it as a general purpose calculator on my smartphone. It's really nice that Numbat is written in Rust :) Will have to try it out.

[deleted]

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

#53

> 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. Why not both? Make lightyears both Length and Time

[deleted]

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

#54
post #23

Earlier quoted context omitted.

Those types of functions are only allowed to take in dimensionless (ie scalar) values. Numbat seems to handle this correctly, see [1]. [1]: https://numbat.dev

I guess that's logical, still a bit tedious in converting values to scalars...

To be fair, thse functions aren't defined for physical quantities.

As a physicist, if you ever see units on the parameter to a trigonmetric function, you can be fairly certain something is wrong.

You can derive this from how e.g. cos(x) can be written as a polynomial series, something like 1 - x^2 + whatever; and since 1 and x^2 would have different units if x is anything but unitless, you've goofed.

That's a big reason why units are used in calculations in the first place. They basically act as a sort of checksum for your calculations.

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

#56

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? I got curious and installed the CLI tool[1] and found that it does indeed account for leap second / leap years: >>> let jahr: Time = 1 year >>> let tage: Time = jahr -> days >>> tage = 365.243 day [Time] References: 0: h…

Just a fun related video from Neil deGrasse Tyson https://youtu.be/mKCvqzCrZfA?si=uW4FOXg2nrqic1ZP

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

#57

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? I got curious and installed the CLI tool[1] and found that it does indeed account for leap second / leap years: >>> let jahr: Time = 1 year >>> let tage: Time = jahr -> days >>> tage = 365.243 day [Time] References: 0: h…

I feel like that’s unit confusion. Converting from year to day should require you to specify what calendar year you’re in to resolve the ambiguity. Otherwise I set an alarm for today + 1 year and things are off by 6 hours. Time is nasty because there’s lots of overloaded concepts and bugs hide in the implicit conversions between meanings. I’m also kinda curious what the underlying type is. Is it a double or do they u…

> I feel like that’s unit confusion. Converting from year to day should require you to specify what calendar year you’re in to resolve the ambiguity.

A year has two meanings - a calendar year, with all the leap days and seconds and timezones, or a duration of time. The latter is still useful, e.g. when someone states that Proxima Centauri is 4.2 light-years away, they don't want to deal with leap-days.

Decent time libraries have separate ways to deal with durations and dates.

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

#58

Can it be used as a date calculator? I didn't see a way to specify "today" or "tomorrow". Like "today" + 14 days etc.

If you're looking for a general solution to that specific type of problem, then dateutils¹ is really useful. It deals with conversions, durations, matching, repeats, etc. It also has a clear and well defined date input format, and being a collection of command line tools it is easy to mangle it in to other tools.

¹ http://www.fresse.org/dateutils

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

#59
post #23

Earlier quoted context omitted.

Those types of functions are only allowed to take in dimensionless (ie scalar) values. Numbat seems to handle this correctly, see [1]. [1]: https://numbat.dev

I guess that's logical, still a bit tedious in converting values to scalars...

You don't have to convert to scalars. Numbers have a type of 1 (= Scalar).

You can just call exp(3), for example: https://numbat.dev/?q=exp%283%29%E2%8F%8E

Or you could pass an angle quantity, which is convertible to a Scalar. Like cos(30 deg): https://numbat.dev/?q=exp%283%29%E2%8F%8Ecos%2830+deg%29%E2%...

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

#60

If I’m reading this correctly, the Frink language has similar features (and also seems darn useful!) https://frinklang.org/

I looked at Frink quite a bit and I agree that it looks cool. But as far as I can tell, it does not have a static type system. At least it's not based on physical dimensions.

And it is not open source.

Post reply on HN