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

Control.Monad.State.Strict.modify is lazy #4

Closed
joeyh opened this issue Mar 9, 2013 · 2 comments
Closed

Control.Monad.State.Strict.modify is lazy #4

joeyh opened this issue Mar 9, 2013 · 2 comments
Assignees

Comments

@joeyh
Copy link

joeyh commented Mar 9, 2013

I've had programs that repeatedly modified state leak memory because modify does not force the f s thunk.

This is surprising in a library with "strict" in its name..

@ekmett
Copy link
Member

ekmett commented Mar 9, 2013

Strict does not refer to the state itself, but rather the tuple, which has two different semantics it is forced to choose between, because lazy state can let more programs terminate than the strict state monad.

You can put $! whatever to get strict assignment.

@ghost ghost assigned ekmett Mar 9, 2013
@ekmett
Copy link
Member

ekmett commented Mar 9, 2013

Changing the semantics of strict state to include forcing the thunk is out of scope.

That said,

1.) It would be a perfectly reasonable request to see about adding a strict-in-the-value State and Writer type to transformers. In particular with Writer there is no recourse by which you can force what you tell in a useful way.

2.) We do have an open issue (#2) to improve the documentation on State.Strict and Writer.Strict to summarize the issue better, to help mitigate confusion.

@ekmett ekmett closed this as completed Mar 9, 2013
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