
Ask HN: Is there any programming language with a Physics-like dimensional types? - jimws
I am curious if there is a programming language with a type system that would cater to types in Physics?<p>For example, I could say:<p><pre><code>  deftype distancd from double;
  deftype time from double;
  deftype speed from distance&#x2F;time;
  deftype acceleration from speed&#x2F;time;

  distance d = 10.5;
  time t = 1.2;
  speed s = d&#x2F;t; &#x2F;&#x2F; okay
  acceleration a = d&#x2F;t&#x2F;t; &#x2F;&#x2F; okay
  acceleration b = d&#x2F;t; &#x2F;&#x2F; error
</code></pre>
Is there any programming language type system that supports this idea?
======
govert
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://docs.microsoft.com/en-us/dotnet/fsharp/language-
reference/units-of-measure) [https://fsharpforfunandprofit.com/posts/units-of-
measure/](https://fsharpforfunandprofit.com/posts/units-of-measure/)

------
GrumpyYoungMan
Mathematica seems to have support for units:
[https://reference.wolfram.com/language/tutorial/SymbolicCalc...](https://reference.wolfram.com/language/tutorial/SymbolicCalculationsWithUnits.html)

------
petra
frink

or this python library : [https://github.com/katerina7479/python-units-of-
measure](https://github.com/katerina7479/python-units-of-measure)

