Settings

Theme

Ask HN: Is there any programming language with a Physics-like dimensional types?

3 points by jimws 6 years ago · 3 comments · 1 min read


I am curious if there is a programming language with a type system that would cater to types in Physics?

For example, I could say:

  deftype distancd from double;
  deftype time from double;
  deftype speed from distance/time;
  deftype acceleration from speed/time;

  distance d = 10.5;
  time t = 1.2;
  speed s = d/t; // okay
  acceleration a = d/t/t; // okay
  acceleration b = d/t; // error
Is there any programming language type system that supports this idea?
govert 6 years ago

I think this is normally done in terms of 'units of measure'. Here's how F# implements this: https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe... https://fsharpforfunandprofit.com/posts/units-of-measure/

GrumpyYoungMan 6 years ago

Mathematica seems to have support for units: https://reference.wolfram.com/language/tutorial/SymbolicCalc...

petra 6 years ago

frink

or this python library : https://github.com/katerina7479/python-units-of-measure

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection