-
Notifications
You must be signed in to change notification settings - Fork 24
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 stack overflow in BoundedEnum (Either _ _) #19
Conversation
Bug spotted by @jacereda |
As part of the work for purescript-contrib/purescript-quickcheck-laws#14 I suppose? Thanks both 😄 |
Yes, and more is coming. |
Ah, merging the other PR has made this one conflict, can you update accordingly please @LiamGoodacre? |
The definition of `toEnum` in the `BoundedEnum (Either _ _)` instance eagerly depended on its own instance. Hid the recursion behind a lambda. Added a regression test for the instance.
@paf31 want to drop the cardinality check here too? |
I don't think you can, since it's used to determine whether the value is in |
Yeah just realised :P |
In that case, thanks 😉 |
Actually we could drop it from the recursive case? |
By that I mean, we can get rid of the bit using our own |
Like this? to :: Cardinality a -> Maybe (Either a b)
to (Cardinality ca)
| n >= 0 && n < ca = Left <$> toEnum n
| otherwise = Right <$> toEnum (n - ca) |
Yeah like that |
Sure, works for me! |
Would this be a possibility as well?
Don't know how slow it would be though. |
Sure, although yeah I think prefer the other option - we're still making the cardinality check so may as well use that info to avoid the extra |
In the other option I guess you can get rid of |
I edited that out immediately after posting it 😄 |
The definition of
toEnum
in theBoundedEnum (Either _ _)
instanceeagerly depended on its own instance.
Hid the recursion behind a lambda.
Added a regression test for the instance.