3 ms·
It seems to me that Haskell would be a great language for such a thing, ensuring correctness at compile time through the type system, e.g. using the units packa
by tobias2014 3y ago
It seems to me that Haskell would be a great language for such a thing, ensuring correctness at compile time through the type system, e.g. using the units package https://hackage.haskell.org/package/units https://hackage.haskell.org/package/units https://github.com/goldfirere/units/tree/master/units https://github.com/goldfirere/units/tree/master/units
It even has nice features like: "The laws of nature have dimensions, and they hold true regardless of the units used. For example, the gravitational force between two bodies is (gravitational constant) * (mass 1) * (mass 2) / (distance between body 1 and 2)^2, regardless of whether the distance is given in meters or feet or centimeters. In other words, every law of nature is unit-polymorphic."
"The units package supports unit-polymorphic programs ..."
If on the other hand you just want a small calculator with units (which actually does also come with a library), there's qalculate ( https://news.ycombinator.com/item?id=37037900 https://news.ycombinator.com/item?id=37037900 )
- actuallyalys 3y agoF# is in the same category of statically typed functional languages, and it has units of measure: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref.... I'm not sure whether it has that level of unit polymorphism, although you can make functions generic over any unit of measure.
- paholg 3y agoRust as well. There are at least a few libraries to do it, but I'll link the one I wrote: https://crates.io/crates/dimensioned https://crates.io/crates/dimensioned