top | item 33481294

(no title)

mdm12 | 3 years ago

Unit of measures are a great example of what a type system can do, and something not enough languages support. F#[1] and Scala[2] are two that I know of that do support UOMs. Like you, I haven't had the need to use them in the domains I work in, but I imagine that they would be invaluable in certain contexts.

[1] https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...

[2] https://github.com/typelevel/squants

discuss

order

throwawaymaths|3 years ago

It's also something that some languages seriously screw up. Consider multiplying a time (which is typed in go) with a numerical value... suppose what I want is a user to input number of time intervals to wait. So the user wants 5, and the interval is 2500 milliseconds. The way you get 12500 milliseconds out of that made me want to throw my computer out the window.

Chinjut|3 years ago

I don't understand. What should you get instead?

leephillips|3 years ago

Julia has this via a package: Measurements.jl.