-
Notifications
You must be signed in to change notification settings - Fork 23
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
lazy+andThen+map3 overflowing the stack #9
Comments
Right now you have a 50% of terminating and a 50% of continuing. Continuing means three chances to continue again. So I think the expected value for the depth is just really high. I am having trouble calculating the expected value of the depth, but I think that's the next step before saying this is an issue with the package. In the meantime, my first instinct is to switch from P.S. I am struggling because the probabilities get real complicated in the
Putting together two uniform distributions does not result in a uniform distribution, but I do not recall enough probability theory to figure it out. Would love to see someone figure it out though! |
@evancz I can try and dust off my math to compute the probabilities 🙂 But I wonder, do you consider this a bug, or just a thing that would happen every now and then? Is this eg. solvable with some kind of trampolining? |
(FWIW, I think the comment about hard depth limit is something worthy of being in the package documentation. It solved my problem.) |
It's pretty easy to use endless : Generator (List Int)
endless =
Random.int 0 20
|> Random.andThen (\x -> Random.map (\xs -> x :: xs) endless) What we're dealing with here though is a computation that might terminate quickly, or might balloon so much that termination becomes increasingly improbable, though never impossible. Either way, I think we're up against the halting problem, so that's not something code can solve. We should advise people to use a hard depth limit, or perhaps a |
In terms of documenting this, where in the documentation should such a note be? Why would someone with this problem be reading the docs for The root issue is that recursion may not terminate, which is not in the API of this library directly. It's just a thing about recursion. So it's not clear to me that this kind of thing can/should be documented in this library. |
I was thinking about putting the note next to |
I agree, it belongs next to Perhaps something like:
|
Use of these three (or maybe two, I'm not sure about
map3
) results in "too much recursion."Ellie with a SSCCE ➡️ https://ellie-app.com/4Kv76dc7Hkpa1
Switching the recursive generators (Plus3 for Plus2) or changing the seed to 1 shows non-failing case.
The text was updated successfully, but these errors were encountered: