{-# LANGUAGE DeriveDataTypeable, BangPatterns #-}------------------------------------------------------------------------------- |-- Module : Data.Acid.Memory.Pure-- Copyright : PublicDomain---- Maintainer : lemmih@gmail.com-- Portability : non-portable (uses GHC extensions)---- AcidState container without a transaction log. Mostly used for testing. --moduleData.Acid.Memory.Pure(IsAcidic(..),AcidState,Event(..),EventResult,EventState,UpdateEvent,QueryEvent,Update,Query,openAcidState,update,update_,query,runQuery)whereimportData.Acid.CoreimportData.Acid.CommonimportControl.Monad.State(runState){-| 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).
-}dataAcidStatest=AcidState{localMethods::MethodMapst,localState::st}-- | 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::UpdateEventevent=>AcidState(EventStateevent)->event->(AcidState(EventStateevent),EventResultevent)updateacidStateevent=caserunStatehotMethod(localStateacidState)of!(result,!newState)->(acidState{localState=newState},result)wherehotMethod=lookupHotMethod(localMethodsacidState)event-- | Same as 'update' but ignoring the event result.update_::UpdateEventevent=>AcidState(EventStateevent)->event->AcidState(EventStateevent)update_acidStateevent=fst(updateacidStateevent)-- | Issue a Query event and wait for its result.query::QueryEventevent=>AcidState(EventStateevent)->event->EventResulteventqueryacidStateevent=caserunStatehotMethod(localStateacidState)of!(result,!_st)->resultwherehotMethod=lookupHotMethod(localMethodsacidState)event-- | Create an AcidState given an initial value.openAcidState::IsAcidicst=>st-- ^ Initial state value. ->AcidStatestopenAcidStateinitialState=AcidState{localMethods=mkMethodMap(eventsToMethodsacidEvents),localState=initialState}