JP Embedded Solutions

A datastore is a monad transformer

In the paper attached to my last post, I proved that any data store is a monad.  Then I proved that if the data was a monoid (so it has a zero and addition) then the store is a monoid too.  And then I asserted that if the data is a monad, then so is the store.  And said I wasn’t going to prove it.

Well, it didn’t fit in that paper, but I thought it was worth writing down.  So, without further ado, I have written a very short note that:

  1. Describes how any data store can be made into a general monad transformer
  2. Shows how, in the case of the trivial monad, this reduces to the simple storage monad described in the other post
  3. Shows that if the underlying data is an additive monad, then so is the data store (which is basically just saying that it’s a monoid with >>=).

And here it is: note on storage as a monad transformer.

About these ads

Filed under: Functional Programming, Haskell, , , , , , ,

2 Responses

  1. Jan Machacek says:

    This is very useful; I am experimenting with monads for storing data (ultimately in some kind of a database–I’m a reformed JEE guy) in Scalad with a little help from Scalaz monads.

    • In that case you might want to look here: Distributed storage in Haskell. In this I introduce the basic storage monad and show that (a) if the data is a monoid then so is the store, (b) if the data is a monoid, it doesn’t matter whether you do monoidal addition on the data or the store.

      If you’re interested in the database angle, something I would like to do is to convert the simple in-memory store described in that paper to a store backed by a database.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Copyright © 2011, JP Embedded Solutions, All rights reserved

All content is subject to the BSD license

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: