Copyright | PublicDomain |
---|---|
Maintainer | lemmih@gmail.com |
Portability | non-portable (uses GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
AcidState container without a transaction log. Mostly used for testing.
Synopsis
- class IsAcidic st where
- acidEvents :: [Event st]
- data AcidState st
- data Event st where
- UpdateEvent :: UpdateEvent ev => (ev -> Update (EventState ev) (EventResult ev)) -> MethodSerialiser ev -> Event (EventState ev)
- QueryEvent :: QueryEvent ev => (ev -> Query (EventState ev) (EventResult ev)) -> MethodSerialiser ev -> Event (EventState ev)
- type EventResult ev = MethodResult ev
- type EventState ev = MethodState ev
- class Method ev => UpdateEvent ev
- class Method ev => QueryEvent ev
- data Update st a
- data Query st a
- openAcidState :: IsAcidic st => st -> AcidState st
- update :: UpdateEvent event => AcidState (EventState event) -> event -> (AcidState (EventState event), EventResult event)
- update_ :: UpdateEvent event => AcidState (EventState event) -> event -> AcidState (EventState event)
- query :: QueryEvent event => AcidState (EventState event) -> event -> EventResult event
- liftQuery :: Query st a -> Update st a
- runUpdate :: Update s r -> s -> (r, s)
- runQuery :: Query s r -> s -> r
Documentation
class IsAcidic st where Source #
:: [Event st] | List of events capable of updating or querying the state. |
State container offering full ACID (Atomicity, Consistency, Isolation and Durability) guarantees.
Atomicity
- State changes are all-or-nothing. This is what you'd expect of any state variable in Haskell and AcidState doesn't change that.
Consistency
- No event or set of events will break your data invariants.
Isolation
- Transactions cannot interfere with each other even when issued in parallel.
Durability
- Successful transaction are guaranteed to survive system failure (both hardware and software).
We distinguish between events that modify the state and those that do not.
UpdateEvents are executed in a MonadState context and have to be serialized to disk before they are considered durable.
QueryEvents are executed in a MonadReader context and obviously do not have to be serialized to disk.
UpdateEvent :: UpdateEvent ev => (ev -> Update (EventState ev) (EventResult ev)) -> MethodSerialiser ev -> Event (EventState ev) | |
QueryEvent :: QueryEvent ev => (ev -> Query (EventState ev) (EventResult ev)) -> MethodSerialiser ev -> Event (EventState ev) |
type EventResult ev = MethodResult ev Source #
Events return the same thing as Methods. The exact type of EventResult
depends on the event.
type EventState ev = MethodState ev Source #
class Method ev => UpdateEvent ev Source #
All UpdateEvents are also Methods.
class Method ev => QueryEvent ev Source #
All QueryEvents are also Methods.
Context monad for Update events.
Context monad for Query events.
Create an AcidState given an initial value.
update :: UpdateEvent event => AcidState (EventState event) -> event -> (AcidState (EventState event), EventResult event) Source #
Issue an Update event and wait for its result. Once this call returns, you are guaranteed that the changes to the state are durable. Events may be issued in parallel.
It's a run-time error to issue events that aren't supported by the AcidState.
update_ :: UpdateEvent event => AcidState (EventState event) -> event -> AcidState (EventState event) Source #
Same as update
but ignoring the event result.
query :: QueryEvent event => AcidState (EventState event) -> event -> EventResult event Source #
Issue a Query event and wait for its result.