-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Fix issue #13352 - Only perform Algebraic arithmetic with allowed types. #2452
Conversation
|
Hm, it seems like the rest of |
|
Ah scratch that, there is |
|
I think it's not a good idea to allow arithmetic operations among values of Algebraic types. I think functional languages don't do that because it muddles the semantics of what an Algebraic data type is. |
It you think of Algebraic as a restricted Variant then it makes sense. |
|
I want to pattern match with a switch on an Algebraic. I don't want to read code written by other people where there's a + among two Algebraic values. Please take a look at what an algebraic data type is, its purposes, look at how they are used and meant in functional languages like Haskell and ML where they are native, and don't add random features to them just because you can in D. Sometimes the point of a language (or library) construct comes from what you can't do with it (like you can't mutate a const, can't print from a pure function, etc). |
|
The thing is that this is already possible and I don't see that it's going to be removed. Based on that I think that crippled support for such operations is worse than one with clean semantic rules (even if even with this pull request they are still far from perfect). Apart from that, there are use cases where such behavior is definitely desired ( |
|
BTW, what's up with the autotester, It seems to just constantly retest everything since many hours. The same seems to be true for most other open pull requests. @braddr, any idea, or is this normal behavior? |
|
AFAIK, whenever any of dmd, druntime, or phobos changes (nowadays basically due to PR merges), the autotester will restart from scratch. I suppose the idea is to ensure that test results are always with the latest bleeding-edge toolchain, and that automerges don't introduce problems into the repos because a code conflict or incompatibility arises between a recently-merged PR and a PR being automerged, that the autotester would miss if it didn't reset everything after each merge. |
|
Yes, this is the case. You can open "Details" to see if there were failures in build history though. |
|
I agree with @s-ludwig about this - while strict tagged union based algebraic type for pattern matching may be interesting addition, changing anything fundamental about existing implementation is not an option and needs to be as good as possible in already defined niche. That PR does the right thing in my opinion. If anything I am more concerned about new restrictions breaking any of existing code. Are there any cases where it did compile before (even if worked wrong) and won't after the PR is merged? |
|
I'm relatively sure that it should only extend the type combinations that work. Cases that before failed for sure, because the result was a The future direction should probably be to extend the code, so that it iterates over the actual types of the |
|
ping |
|
This is in dire need of more reviewers (change is not trivial) @DmitryOlshansky @monarchdodra @JakobOvrum ? |
|
I recall looking at this PR before and overall I like it. Will re-review later today. |
5ef6476
to
c39b621
Compare
| string tryUseType(string tp) { | ||
| import std.string : format; | ||
| return q{ | ||
| static if (allowed!%s && T.allowed!%s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use %1$s for the format specifier everywhere and then pass tp only once.
Adds a static check allowed!T before trying any particular numeric type. Also checks for an exact type match in case of a raw (non-Variant) operand and prefers that to one of the fixed numeric types. Finally, it loosens the restriction for opArithmetic to only work for equal Variant types. Conflicts: std/variant.d
c39b621
to
6c04790
Compare
|
Ok, it LGTM now. Anyone else have comments? |
|
Still LGTM :) |
| result = mixin("get!(double) " ~ op ~ " other.get!(double)"); | ||
| else | ||
| result = mixin("get!(real) " ~ op ~ " other.get!(real)"); | ||
| string tryUseType(string tp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the Phobos bracket style
|
Auto-merge toggled on |
Fix issue #13352 - Only perform Algebraic arithmetic with allowed types.
Adds a static check allowed!T before trying any particular numeric type. Also checks for an exact type match in case of a raw (non-Variant) operand and prefers that to one of the fixed numeric types. Finally, it loosens the restriction for opArithmetic to only work for equal Variant types.
https://issues.dlang.org/show_bug.cgi?id=13352