TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

3 点作者 jimws超过 5 年前
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 条评论

govert超过 5 年前
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>
GrumpyYoungMan超过 5 年前
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>
petra超过 5 年前
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>