Consider that

interface PasswordStore {
  void store(Path path, String secret, Map metadata);
}

is identical to

void store (PasswordStore store, Path path, String secret, Map metadata)

or

store :: PasswordStore -> Path -> secret -> MetaData -> IO ()

So, you can treat PasswordStore as a pure data structure (that has things like connection details) and just define functions that use it.  I wouldn't worry about grouping the functions together.(*) I'm going to assume you don't really need an actual interface, but if you did, you could investigate typeclasses.

Julian.

(*) In general terms, the only reason to group functions together is to enforce laws that relate the behaviours together e.g. that you can retrieve something you stored.

On 4 January 2015 at 11:14, Thomas Koch <thomas@koch.ro> wrote:
Hi,

I'm writing a password manager that implements a dbus-api using the dbus[1]
package. I'd like to separate the code that implements from the dbus api from
the code that stores and retrieves the secrets (passwords). In Java I'd use an
interface, e.g.:

interface PasswordStore {
  void store(Path path, String secret, Map metadata);
  (String secret, Map metadata) retrieve(Path path);
  (String secret, Map metadata) search(Map criteria);
}

And the dbus-api would export this interface:

dbusClient.export(PasswordStore store)

What would be a Haskell way to do the same? My only idea is to define a record:

data PasswordStore {
    store :: Path -> Secret -> MetaData -> IO ()
  , retrieve :: Path -> IO (Secret, MetaData)
  , search :: Criteria -> IO (Secret, MetaData)
}

Thank you for any suggestions! Thomas Koch

[1] http://hackage.haskell.org/package/dbus-0.10.9
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners