TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

3 pointsby jimwsover 5 years ago
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?

3 comments

govertover 5 years ago
I think this is normally done in terms of &#x27;units of measure&#x27;. Here&#x27;s how F# implements this: <a href="https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fsharp&#x2F;language-reference&#x2F;units-of-measure" rel="nofollow">https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fsharp&#x2F;language-refe...</a> <a href="https:&#x2F;&#x2F;fsharpforfunandprofit.com&#x2F;posts&#x2F;units-of-measure&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fsharpforfunandprofit.com&#x2F;posts&#x2F;units-of-measure&#x2F;</a>
GrumpyYoungManover 5 years ago
Mathematica seems to have support for units: <a href="https:&#x2F;&#x2F;reference.wolfram.com&#x2F;language&#x2F;tutorial&#x2F;SymbolicCalculationsWithUnits.html" rel="nofollow">https:&#x2F;&#x2F;reference.wolfram.com&#x2F;language&#x2F;tutorial&#x2F;SymbolicCalc...</a>
petraover 5 years ago
frink<p>or this python library : <a href="https:&#x2F;&#x2F;github.com&#x2F;katerina7479&#x2F;python-units-of-measure" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;katerina7479&#x2F;python-units-of-measure</a>