[Haskell-cafe] Persisting a Map

Mikael Brockman mbrock at goula.sh
Thu Dec 19 09:42:15 UTC 2013

Andrew Cowie <andrew at operationaldynamics.com> writes:

> Yeah, if external inspection were necessary that'd definitely be a good
> reason to go that way for sure. The report from Ozgur that just
> serializing out a Map structure was workable is encouraging, though.
> I'll start with that.

Pardon the digression, but I'd just like to appreciate this way of
thinking.  There's a rant by Bob Martin [1] that concludes:

> "We are heading into an interesting time. A time when the prohibition
> against different data storage mechanisms has been lifted, and we are
> free to experiment with many novel new approaches. But as we play with
> our CouchDBs and our Mongos and BigTables, remember this: The database
> is just a detail that you don’t need to figure out right away."

A project I'm working on uses a persistent append-only list, which is
currently implemented like this, almost verbatim:

  async . forever $
    atomically (readTChan queue) >>= writeFile path . Aeson.encode

Files are trivial to back up and generally easy to work with.  Since
it's just JSON, I can grep and mess with it easily with command-line
tools.  And since the writing is done in a separate thread reading from
a queue, I don't need to worry about locking.

I think this will be alright for a good while, and when the project
outgrows it, I'll just migrate to some other solution.  Probably
acid-state, because the version migration stuff seems really useful.

[1]: Bob Martin's rant "No DB",

Mikael Brockman

More information about the Haskell-Cafe mailing list