Why not both? Make lightyears both Length and Time
Show HN: Numbat – A programming language with physical dimensions as types
51–60 of 122 posts
Re: Show HN: Numbat – A programming language with physical dimensions as types
#52Frink ( 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.
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
Re: Show HN: Numbat – A programming language with physical dimensions as types
#54Earlier 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...
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
#55It’s interesting that they support currency units. Wonder how the conversion works. Probably have to provide conversion factor as well?
Re: Show HN: Numbat – A programming language with physical dimensions as types
#56How 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…
Re: Show HN: Numbat – A programming language with physical dimensions as types
#57How 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…
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
#58Can it be used as a date calculator? I didn't see a way to specify "today" or "tomorrow". Like "today" + 14 days etc.
Re: Show HN: Numbat – A programming language with physical dimensions as types
#59Earlier 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 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
#60If I’m reading this correctly, the Frink language has similar features (and also seems darn useful!) https://frinklang.org/
And it is not open source.