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/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
</code></pre>
Is there any programming language type system that supports this idea?
I think this is normally done in terms of 'units of measure'. Here's how F# implements this: <a href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure" rel="nofollow">https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...</a>
<a href="https://fsharpforfunandprofit.com/posts/units-of-measure/" rel="nofollow">https://fsharpforfunandprofit.com/posts/units-of-measure/</a>
Mathematica seems to have support for units: <a href="https://reference.wolfram.com/language/tutorial/SymbolicCalculationsWithUnits.html" rel="nofollow">https://reference.wolfram.com/language/tutorial/SymbolicCalc...</a>