Skip to content

morganthomas/Shpadoinkle-continuations

Repository files navigation

Shpadoinkle continuations

Shpadoinkle continuations (henceforth just "continuations") offer a strategy for updating a single state TVar atomically when other threads may be updating the same state TVar at the same time and you may need to perform IO actions during the process of updating the state. Continuations are similar to STM transactions, but unlike STM transactions, you can perform IO actions inside of a continuation. The motivating application is Shpadoinkle, a programming model for declarative, high performance user interface.

A Continuation can be Done (no update), or it can contain a pure state updating function and a function from the value of the state to an IO action which produces another Continuation. The state update produced by a Continuation is the composition of all of the pure state updating functions in the stages of the continuation. This state update is done atomically after all the stages of the continuation have been computed and the side effects of their computation performed. During the execution of the continuation, the successive stages of the continuation see the current state of the TVar as if the state updates of the previous stages had already been performed. However, these updates are not visible to the rest of the program until they are performed atomically all at once after the continuation has run.

Additionally, Continuations feature a Rollback capability. When a continuation reaches a Rollback stage, it discards all state updates created by the continuation so far. The pure state updating functions generated by the previous stages of the continuation will no longer be used on the current state to create the state seen by the subsequent stages of the continuation, and they will not be used to update the state atomically at the end of the continuation, so that only the pure state updating functions generated by the stages after the Rollback will have a final effect on the state.

You can update a TVar using both continuations and other atomic transactions at the same time. They should interoperate smoothly with each other.

Continuations can be used for functional reactive programming. The function shouldUpdate included in Control.Continuation is helpful for this. You can use shouldUpdate to set up handlers which should be triggered when the value of a TVar changes.

About

Continuations for atomic updates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published