You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
One initializes acid by opening up a checkpoint of the state, and providing an initial value if there's no checkpoint, with
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:
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 likeavailable 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.
The text was updated successfully, but these errors were encountered: