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

RFE: openLocalStateIO #47

Open
dmwit opened this issue Dec 1, 2014 · 0 comments
Open

RFE: openLocalStateIO #47

dmwit opened this issue Dec 1, 2014 · 0 comments

Comments

@dmwit
Copy link

dmwit commented Dec 1, 2014

One initializes acid by opening up a checkpoint of the state, and providing an initial value if there's no checkpoint, with

openLocalState :: Sane st => st -> IO (AcidState st)

This works well for applications with a sensible static default state; but in general programs may want to do some computation to produce an initial state. In particular, for random number generator seeding, one often has to do some IO to pick a suitable initial seed. One would like to avoid doing this IO unless it's necessary (in the case of seeding a PRNG the call may block until enough entropy is available, for example, and in any case consumes a limited resource). Something like the following is already possible:

main = do
    seed <- unsafeInterleaveIO pickASeed
    acid <- openLocalState seed
    -- etc.

However, this is a bit awkward; uses of unsafe* are naturally a point of contention. A more ideal solution would be to have an initializer with a type like

openLocalStateIO :: Sane st => IO st -> IO (AcidState st)

available in the acid-state API, which promises to execute its argument only when the state can't be found on disk. IO-variants of other similar functions might be welcome for other users, too.

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

No branches or pull requests

1 participant