-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Ported IO#ensuring (and renamed to avoid mass confusion) #1662
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b86f987
Ported IO#ensuring (and renamed to avoid mass confusion)
djspiewak 4e5ffcc
Merge branch 'master' into feature/ensuring
djspiewak 340157b
Added tests for MonadError#guarantee
djspiewak dac34b9
Merge branch 'master' into feature/ensuring
djspiewak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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.
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.
can we add a test of some kind to this?
I mean, even adding a reimplementation of this code to the laws for MonadError along with an example exercising it.
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.
👍 on adding to law. maybe also add quick doctest as an example and to provide coverage for the syntax code.
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.
A law would be useless, since it would over-constrain implementations. The only useful overrides of
guarantee
would be for implementations which have it as a structural primitive, but in that caseguarantee
would not be equivalent toflatMap
composed withattempt
. So it would be a very round-about way of making the functionfinal
and running a ton of redundant tests.The right thing to do is add a test, but unlike
MonadTest
,MonadErrorTest
doesn't currently exist. I'm all in favor of adding it, but this falls into the category of things that are somewhat harder to work on (since I have to figure out how all that stuff works). Incoming sometime in the next few days, hopefully.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.
I added the
MonadTests
, it's basically just a vanilla scalatests suite.It should be trivial to create aMonadErrorTest
class and just write regular scalatests tests forguarantee
in it.Update: actually there is already a
MonadErrorTest
it's calledMonadErrorSuite
, we should probably rename it.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.
@djspiewak If
guarantee
is a structural primitive, it must still behave asflatMap
composed withattempt
, no? I don't see how anything otherwise could be the case. What is the difference between a law and a test in this case?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.
I was thinking of a situation where a datatype adds extra guarantees to
guarantee
, meaning that it would have distinct semantics fromflatMap
composed withattempt
. I certainly can't prove that this is impossible, so I wouldn't want to rule it out completely with a law.In general, I feel like concrete convenience functions (like this one) should be tested with tests, not laws, especially when their behavior follows trivially from other laws.
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.
I need to see tests here specified in terms of the "bracket problem" (see http://hackage.haskell.org/package/layers-0.1/docs/Documentation-Layers-Overview.html#g:9 and the next couple sections).
I am not convinced this belongs on MonadError. As we've discussed previously, a monad layer being able to return an error has nothing to do with the rest of the effects in the stack being able to halt the computation, which is what
guarantee
exists to guarantee semantics for.