Open
Conversation
Owner
|
I'm not looking to change main.rs, but if you'd like to add this implementation in another file (with proper attribution to yourself and willcrichton), I'm happy to merge. |
Contributor
Author
No problem, don't hesitate to close this PR without merging. I just wanted to preserve this for my own future reference, for which this PR is sufficient. For the record: This reduces the "monstrosity" mentioned in https://fprasx.github.io/articles/type-system-arithmetic/ to: type RawQuotient<T, U> = Add<Succ<Zero>, Div<Sub<Succ<T>, Succ<U>>, Succ<U>>>;
impl<T, U> DivImpl for (Succ<T>, Succ<U>)
where
(T, U): SubImpl,
(Sub<T, U>, Succ<U>): DivImpl,
(Succ<Zero>, Div<Sub<T, U>, Succ<U>>): AddImpl,
(
GreaterThanEq<T, U>,
Add<Succ<Zero>, Div<Sub<T, U>, Succ<U>>>,
): MulImpl,
(T, U): GreaterThanEqImpl,
{
// If x < y, return 0. We can do this by multiplying the "RawQuotient" by
// the bool->int value of this condition.
type Output = Mul<GreaterThanEq<Succ<T>, Succ<U>>, RawQuotient<T, U>>;
}It's still quite a mouthful, but I think better than before and I think it is now short enough to inline A more concise implementation is available at fprasx/fprasx.github.io#1 (comment). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains two orthogonal changes:
typedefinition per operatorimpls themselves are simplifiedI combined the two because the second is easier to do in the simplified code after the first change.
I found out that the
impls can be simplified by reading https://github.com/willcrichton/tyrade/blob/master/src/tnum.rs. I extended that idea to the other operators as well.