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.

Doing First Grade Math in Rust's Type System

9 pointsby BD103over 1 year ago

1 comment

algasover 1 year ago
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 未加载