Live data from Hacker News

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

numbat.dev

61–70 of 122 posts

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

#61

Earlier quoted context omitted.

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 rea…

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

Exactly. Which is why trigonometric functions in Numbat have the signature

  cos(x: Scalar) -> Scalar
and only take quantities as arguments that are implicitly convertible to a scalar, like 'cos(pi / 3)', 'cos(30 deg)' or 'cos(0.5 turn)'.

Whether or not angles should be considered dimensionless is actually a matter of academic dispute. If you want to know more, take a look at https://github.com/sharkdp/numbat/pull/167 and the references therein.

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

#62

Earlier quoted context omitted.

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 rea…

Radians vs degrees?

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

#63
post #5

I can't resist mentioning F# Units of Measure aka UoM :) https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...

F# is the only language I looked at that has a really powerful unit system. The author of that unit system wrote his PhD thesis on the subject [1]. Numbat's type system is actually pretty close to what was suggested in that thesis (in contrast to F#'s system, which is based on units — not dimensions).

[1] https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-391.pdf

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

#64
post #49

the classic problem for such number systems is linear algebra https://yosefk.com/blog/can-your-static-type-system-handle-l... 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 i don't see anything in https://numbat.dev/doc/type-…

No, we do not have aggregate types in Numbat yet. But it is definitely something I would like to support.

Note that it is possible to construct a type system solution to this problem (vectors/matrices with non-uniform units). A colleague of mine has an excellent talk on this: https://www.youtube.com/watch?v=SLSTS-EvOx4

By 'Scalar', in the document you referenced, we mean a dimensionless quantity. Not a scalar in the scalar-vector-matrix-tensor sense. Maybe I should rethink that notation.

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

#65

A month cannot be unambiguously represented as a length of time, as the length of a month is variable.

It looks as if they're defining a month as some amount of days. (30.4369, given the following.) >>> 1 day + 1 month 1 day + 1 month = 31.4369 day

    >>> 1 month -> seconds
        = 2_629_746 s    [Time]
Just playing around with this and really enjoying it.

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

#66

Earlier quoted context omitted.

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 rea…

Radians vs degrees?

Radians, gradians, degrees, minutes, seconds, thirds, revolutions are all ways of dividing up a circle

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

#67

Earlier quoted context omitted.

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 li…

Except there is also https://en.m.wikipedia.org/wiki/Sidereal_year So I would say they need explicit different years.

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

#68
post #10

You don't need a new programming language for something that C++ templates with integer constants give you for free.

Came here to say this. As soon as I saw the first example on the linked web page, I immediately thought of C++. Reinventing the wheel.

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

#69

Earlier quoted context omitted.

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 rea…

Radians vs degrees?

For radians, we can note that the length of a circle segment is rα, where r is the radius and α is the angle, where both the radius and circle segment have dimensions length; then we must infer that α is dimensionless.

Degrees follow a similar argument.

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

#70

This is really cool! 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?

Thank you.

I don't think we diverge from units on purpose anywhere, but I am probably not very familiar with its syntax, to be honest. I did however look at its huge collection of units and checked if there were any important units missing. I think we have a pretty comprehensive list of units that are supported by now in Numbat [1].

[1] https://numbat.dev/doc/list-units.html

Post reply on HN