HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Moduleacid-state-0.16.1.4Haskell2010

Data.Acid

AcidState container using a transaction log on disk.

To see how it all fits together, have a look at these example https://github.com/acid-state/acid-state/tree/master/examples.

  • 5 types
  • 3 classes
  • 9 values
  • Packageacid-state-0.16.1.4
  • Exports17
  • LanguageHaskell2010
  • LicenceLicenseRef-PublicDomain
  • SourceAcid.hs
datadata AcidState st
#

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 unexpected system shutdowns (both those caused by hardware and software).

valueopenLocalState
  1. :: (Typeable st, IsAcidic st, SafeCopy st)
  2. => st

    Initial state value. This value is only used if no checkpoint is found.

  3. -> IO (AcidState st)
#

Create an AcidState given an initial value.

This will create or resume a log found in the "state/[typeOf state]/" directory.

valueopenLocalStateFrom
  1. :: (IsAcidic st, SafeCopy st)
  2. => FilePath

    Location of the checkpoint and transaction files.

  3. -> st

    Initial state value. This value is only used if no checkpoint is found.

  4. -> IO (AcidState st)
#

Create an AcidState given a log directory and an initial value.

This will create or resume a log found in directory. Running two AcidState's from the same directory is an error but will not result in dataloss.

valueupdate
  1. :: UpdateEvent event
  2. => AcidState (EventState event)
  3. -> event
  4. -> IO (EventResult event)
#

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.

newtypenewtype Update st a
#

Context monad for Update events.

Instances4MonadState, Monad, Functor, Applicative
newtypenewtype Query st a
#

Context monad for Query events.

Instances4MonadReader, Monad, Functor, Applicative
  • MonadReader st (Query st)Defined in acid-state-0.16.1.4 · Data.Acid.Common
  • Monad (Query st)Defined in acid-state-0.16.1.4 · Data.Acid.Common
  • Functor (Query st)Defined in acid-state-0.16.1.4 · Data.Acid.Common
  • Applicative (Query st)Defined in acid-state-0.16.1.4 · Data.Acid.Common
valuemakeAcidic :: Name -> [Name] -> Q [Dec]
#

Create the control structures required for acid states using Template Haskell.

This code:

myUpdate :: Argument -> Update State Result
myUpdate arg = ...

myQuery :: Argument -> Query State Result
myQuery arg = ...

$(makeAcidic ''State ['myUpdate, 'myQuery])

will make State an instance of IsAcidic and provide the following events:

data MyUpdate = MyUpdate Argument
data MyQuery  = MyQuery Argument