Doing First Grade Math in Rust's Type System(fprasx.github.io) |
Doing First Grade Math in Rust's Type System(fprasx.github.io) |
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)
Rational numbers can similarly be defined by new operations and equivalence relations on the product set Z x Z. I don't know enough Rust to say whether it's feasible to implement this in the type system, but I'd be curious to hear from someone more experienced!I think that building rationals on top of it would be pretty easy, though not necessarily performant.