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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Doing First Grade Math in Rust's Type System

9 点作者 BD103超过 1 年前

1 comment

algas超过 1 年前
Interesting article! Given that subtraction isn&#x27;t closed on the natural numbers, I wonder if it would be possible to implement subtraction as operations on a new type (Integer, Z):<p><pre><code> Z = N x N (Cartesian product or sum type) for p, q in Z: p=q if p.first + q.second = q.first + p.second p + q := (p.first + q.first, p.second + q.second) p - q := (p.first + q.second, p.second + q.first) </code></pre> Rational numbers can similarly be defined by new operations and equivalence relations on the product set Z x Z. I don&#x27;t know enough Rust to say whether it&#x27;s feasible to implement this in the type system, but I&#x27;d be curious to hear from someone more experienced!
评论 #38978132 未加载