persistence - Use acid-state like event log in Haskell -
i'm using acid-state in project , quite it. how easy add persistence plain haskell datatypes without boilerplate.
as far understand, acid-state keeps log of events, instead of writing out entire new state on every update. i'm looking way me review log of recent changes state within application, (read-only) list. (something git log
, though don't need branching or being able go older commit.)
of course can write own separate log file details of state changes, or model data list of diffs, prefer automatic , allows me use plain datatypes as possible.
is there library similar acid-state, or perhaps internal functionality of acid-state use this?
here's approach ended with:
i using wrapper around data.acid.update
(because it's running in monad restricted io) , realized wrapper store event own log. updateevent update
constraint implies safecopy update
, runput . safeput
can serialize bytestring
. however... binary representation, not intended humand-readable, , wanted able review it. realized reading acid-state event log disk have same problem.
so added show update
constraints of wrapper. @ every place uses state added:
{-# language standalonederiving #-} ... $(makeacidic ''state ['update]) deriving instance show update
(standalonederiving might little controversial, not cause problem orphans here, it's in same file.)
in wrapper call show
on update , write result own log file. of course loses atomicity of update: possible application crashes between update
call , own logging call, i'm willing accept risk.
Comments
Post a Comment