-
Notifications
You must be signed in to change notification settings - Fork 2
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
Postpone: Add MonadThrow to UniformRange #115
base: interface-to-performance
Are you sure you want to change the base?
Conversation
Thanks for this proposal! This would break two examples in the top level docs (which I haven't been able to hook up to doctests), please fix those: Line 25 in bb2d26a
Lines 40 to 42 in bb2d26a
I would also like to see confirmation that this does not impact performance in a big way. I just merged #114 which should make it easier to compare a benchmark run off |
This PR suggests throwing a synchronous exception when the caller violates a precondition in the interval definition, e.g. the precondition "do not use generator functions with an empty interval". Arnaud Spiwack's recent blog post contains this in the list of circumstances where one should use imprecise exceptions (
(https://www.tweag.io/posts/2020-04-16-exceptions-in-haskell.html) This suggests that we should use an imprecise exception ( Attempting to generate values in an empty interval does sound like a programming error to me, which suggests that user code should validate that it is using sensible bounds before it calls What do you think? E.g. what good code patterns do synchronous exceptions enable? |
@curiousleo I'll start with the fact that I don't agree with Arnaud Spiwack on usage of imprecise exceptions. Taking division by zero as an example. In order to throw The only time I accept usage of I would be ok with switching to
Another thing I never got a chance to comment on is I think it was a bad idea to place examples into cabal file. Description of package should be high level instead of a short tutorial. Moreover these examples are available in haddock, so I really see no point in duplicating them |
One more thing I forgot to mention. If I am writing a reusable function without knowing the actual type of the data that will be generated, I do not know ahead of time what input I should check to |
I want to point out that depending on It's also trivially easy to convert MonadThrow based code to code that just throws exceptions around. Just use newtype Partial a = Partial { partial :: a }
deriving Functor,Applicative,Monad via Identity a
instance MonadThrow Partial where
throwM = throw EDIT: Maybe/Either, exceptions. What did I think? |
In light of #113 (comment) and #113 (comment), I think we can shelve this for now: AFAICT this PR prepares the way to a clusivity API, which we have decided not to focus on for v1.2. The discussion that's already happened here is still valuable once we pick up clusivity API work again, so I'm happy to leave this open - as you prefer. If so, perhaps mark it as |
For now
uniformRM
doesn't fail any where, this PR just prepares the types for failure