logoalt Hacker News

simionestoday at 9:16 AM1 replyview on HN

This is precisely why (programming language) types are poor model of physics units, despite often being touted for this exact use case. 3m is not the same thing as "the value 3 of type meter". It is the multiplication of the dimensionless scalar 3 with the special "m" constant for meters.

That's why pow(3m, 2) = 9 m^2, and not `the value 9 of type meter`. Of course, you can define the type `square meter` as well, and define `pow -> meters -> positive integer -> square meters`. However this quickly becomes overwhelming once you start doing more complex expressions with multiple types. What is the type of `pow (3kg^2 * m/s, 3/2)`?

Edit to add: also, there is a simple fact that "sin(pi/2 kg)" is just not defined, in programming or math or physics or any other useful system. It's definitely not 1kg, just like sin ( (pi/2) * 2) is not sin (pi/2) * sin (2).


Replies

xg15today at 10:36 AM

> with the special "m" constant for meters.

Isn't the "special constant" exactly "value 1, type meters", defined as equal to "value <...very large number...> type atoms" etc?

If not, then what would be the result of the multiplication of 3 with "m"?

> Of course, you can define the type `square meter` as well, and define `pow -> meters -> positive integer -> square meters`

As long as your power is an integer, you can reduce it to multiplication. So what you'd really want to define is the result of "<value1 of type meter> * <value2 of type meter>", "(<value1 of type meter> * <value2 of type meter>) * <value3 of type meter>" etc.

What this gets you in the end is a type algebra, but that is also not exactly a new concept.

show 1 reply