Return Failure early in <* and *> too#190
Conversation
chshersh
left a comment
There was a problem hiding this comment.
Thanks for your contribution! However, I propose an alternative solution to this problem.
Short-circuiting behaviour of these operators can be tested manually via some unit tests later.
9a7467f to
11235fb
Compare
|
I also added a unit test to ensure the short-circuiting works correctly, for all of the |
11235fb to
0f3dd68
Compare
chshersh
left a comment
There was a problem hiding this comment.
Thanks! I feel like documentation for the Validation module can be improved. But I have plans on how to do this and will do it separately 👍
vrom911
left a comment
There was a problem hiding this comment.
Sorry, I'm slow, but I don't see the point of these changes 🤔 Could you please explain what benefits this PR gives the library?
|
Consider this code: case thisWillFail *> thisWillTakeALongTime of
Failure _ -> print "It didn't work."
Success _ -> print "It worked!"Since we know that the whole expression will be a |
chshersh
left a comment
There was a problem hiding this comment.
After thinking more about this PR and discussing it with @vrom911, I now believe that removing code and potentially breaking working code is not a good idea. In general, it's preferable to avoid changing the code in such a considerable way without confidence. And the current example in the documentation is also not helpful. So let's not merge this PR until we have better testing and documentation story for Validation.
|
Sure, I do understand that, but I'm talking exactly about this PR. This feels like unchecked breaking change. @chshersh are you sure you would like to take such a risk? I'm personally using |
|
Am I missing something? How is this a breaking change? |
|
@vrom911 Agree with you here. I'm also using |
|
Actually, this is worse than just a performance problem; we're not a valid Applicative:
(emphasis mine) Ours aren't equivalent. If |
0c0f088 to
0bb792e
Compare
|
Now that #176 is fixed, is this ready to merge? |
|
@josephcsible Well, since we have tests now, we actually can implement our own more optimised versions of these operators (like it how was done at first). Because now we have more guarantees that they will work. And we won't rely on the inliner too much as a pleasant consequence. |
ad32489 to
22d30b2
Compare
|
@chshersh Done. |
chshersh
left a comment
There was a problem hiding this comment.
@josephcsible Thanks for the refactoring, looks good 👍
| >>> liftA2 (+) a c | ||
| Failure ["Not correct"] | ||
|
|
||
| >>> [x | Success x <- [ha <*> e, c <* e, d *> e, liftA2 (+) d e]] |
There was a problem hiding this comment.
Heh, I wish these variable names could make a little sense, so the examples could become useful 😢
@chshersh should I create an issue for refactoring this?
Checklist:
HLint
hlint.dhallaccordingly to my changes (add new rules for the new imports, remove old ones, when they are outdated, etc.)..hlint.yamlfile (see this instructions).General
stylish-haskellfile.[ci skip]text to the docs-only related commit's name.