Skip to content
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

Incorrect example in the documentation #188

Open
sarahzrf opened this issue Aug 10, 2018 · 1 comment
Open

Incorrect example in the documentation #188

sarahzrf opened this issue Aug 10, 2018 · 1 comment

Comments

@sarahzrf
Copy link

sarahzrf commented Aug 10, 2018

This example is incorrect:

> mdo
> let price = 50 :: Int
> bAmount <- accumB price $ unions
> [ subtract 10 <$ eCoin
> , const price <$ eSold ]
> let eSold = whenE ((<= 0) <$> bAmount) eCoin

I know it's not exactly a bug, but I did lose like 5 minutes puzzling over it because I couldn't see how the code produced the wanted behavior—in fact, it doesn't! The machine does not vend the juice once there's 0 remaining and then reset the cost to 50; it vends it once you insert a coin after there's 0 remaining, resets it to 50, and then credits the new coin. This does produce the behavior of vending after every 5 coins (except for the first time, which requires 6), but it's still a confusing example.

I set up a minimal runnable example for this code and recorded a demo run.

@HeinrichApfelmus
Copy link
Owner

Ah, I see, because the Behavior still has the value before inserting the coin that should bring it to zero or below. That is an issue, indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants