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
Extra Sync[F] laws for map and flatMap #71
Comments
I'm 👍 on Exceptions are the result of side effects and even though we expect people to pass pure functions in Thus this is also a problem of usability. Instead of having only one mechanism for dealing with exceptions (e.g. Actually these laws really have to be available for |
While in principle I agree with this idea (especially for So while I agree that leaving things undefined in terms of |
I'm going to close this for now. Scalaz 8's I also think, upon long discussion with @jdegoes and others, that this is really one of those subjective design decisions that shouldn't be enforced. Specifically, cats-effect pure f <*> pure x = pure (f x) Rewritten into a slightly more familiar style in Scala (using val left = for {
a <- F.pure(f)
b <- F.pure(x)
} yield a(b)
left <-> F.pure(f(x)) If we instantiate As a pedagogical note, these are the sorts of examples which motivate the oft-cited fact that throwing an exception is pure, but catching one is impure. You cannot see the violation of the applicative laws without At any rate, I'm not comfortable codifying behavior into a law which in turn conflicts with behavior codified into another law applied to the same abstraction. And for the same reason, I'm not comfortable telling people that the cats-effect semantic is objectively the one and correct way of doing things. It's still the right approach in my view, but I admit arguments to the contrary. Thus, we will not be codifying this semantic in the laws. |
SyncLaws[F]
have nothing to say about the result of throwing an exception from within a function passed tomap
orflatMap
being equivalent to the result of usingraiseError
. To my mind this is one of the biggest practical differences betweenSync
andMonadError
, becauseMonadError
is incapable of offering this as a law (despite the instances forTry
andFuture
doing so).I think this is necessary because all of the exception-centered mechanisms in cats-effect being fully-specified greatly decreases the chance of unsound usage and relying by accident on properties which are not necessarily shared in common by all
Sync
instances; I also think it's more consistent, seeing as behavior likeF.delay(throw e) <-> F.raiseError(e)
is defined as a law.The text was updated successfully, but these errors were encountered: