-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GATs could eliminate the need for traits for the operations #191
Comments
That's really neat! Definitely a huge ergonomic improvement. Not sure if it would be a breaking change to add to typenum's traits, but worst case, we could create new traits. |
I'd say worst case you have a major revision bump. |
I'm taking a stab at implementing this. I managed to get I don't think it will be possible (nor, to be honest, desireable) to create this in a backwards-compatible way. The new API is so much simpler that downstream code would mainly have to 'throw most bounds away' to upgrade. |
Managed to get So that will need to be changed to the more complicated binary long division 🤐 . |
I’m revisiting this again, and have some new ideas to further reduce the number of associated types traits like In any case, if me or someone else, re-implements at least some nontrivial algorithms of typenat in a GATty manner, one of the concerns should be not to make the thing perform a lot worse. On that note, I’m wondering: Is there any performance benchmarks for typenum? I’ve spotted mentions such as on Typical benchmarks are for run-time, though compilation time can of course also be measured, but I’m not sure where to find example use-cases that make heavy use of typenat computation that could be measured in compile-times. Do we have something like that somewhere? |
I definitely had some rudimentary performance benchmarks, but I guess I never committed them. I think I just had a python script that generated a bit of Rust code that performed a division, and looped through larger and larger numbers. This was fine for the issue at the time (exponential time for division), but I'm not sure it'd be as useful for a general purpose benchmark. |
I haven’t studied use-cases of
typenum
too deeply, so I’m not sure how beneficial this is in the first place… and implementing this would also possibly be somewhat of a breaking change (?) (or maybe not?)… but as far as I understand, as of now, it’s not possible to state simple bounds such asI: Integer, J: Integer
and then do an additionop!(I + J)
on them. You would need an additionalI: Add<J>
bound. And I just realized that with GATs this doesn’t need to be the case anymore. I had that insight when writing something likeand as we (should) all know, if nand is possible, then everything is possible :-)
Here’s a longer example / proof of concept (click me!)
Below is an example implementation of unsigned integer addition. This is simply the first implementation I came up with, I’m claiming neither that it’s particularly beautiful, nor optimal in any manner.
I’m posting this here, because I’m not sure if that’s a known thing yet :-)
Also I’m not 100% certain whether there isn’t any non-GAT way of doing the same, but I couldn’t come up with any approach so far, so maybe this really is a new thing that GATs allow us to do?
The text was updated successfully, but these errors were encountered: