willcrichton / tyrade

A pure functional language for type-level programming in Rust
323 stars 13 forks source link

Use typenum for type-level integers #1

Open RustyYato opened 4 years ago

RustyYato commented 4 years ago

Currently this crate uses peano arithmetic, but this is too inefficient in many cases (especially as numbers grow in size). It would be better to use typenum which offers all arithmetic operations in O(log(n)) time as the default. (I think we still need to keep the peano arithmetic because there are cases where it is more efficient, for example when counting things).

https://github.com/paholg/typenum

willcrichton commented 4 years ago

Copying from my /r/rust comment:

The Peano numerals are just to test out the internal consistency of the system. The only barrier to using typenum would be the trait vs. type alias convention. The compiler assumes that any function call F(X, Y) can compile into F<X, Y> along with the bound X: ComputeF<Y>. So either you could write a Tyrade-friendly wrapper API for typenum, or add a typenum extension to the compiler.

Someone just needs to do that part, and we can integrate it.