haskell - Generalizing the functions of a key/value database for both on disk (IO) and pure cases? -
the basic functions of key value database store, fetch, , delete. i'm attempting write typeclass allows return types of these functions either pure or in io can write single engine works both in-memory data.map backed implementation , on-disk implementation.
the pure typeclass might this:
class purequeryable d fetch :: d -> key -> maybe value insert :: d -> key -> value -> d delete :: d -> key -> maybe d ...whereas io typeclass might this:
class ioqueryable d fetch :: d -> key -> io (maybe value) insert :: d -> key -> value -> io d delete :: d -> key -> io (maybe d) i'm attempting combine these two, , suggested (vektorweg1) on #haskell wrote this:
class queryable d r fetch :: d -> key -> ??? insert :: d -> key -> value -> ??? delete :: d -> key -> ??? i unsure of write in place of ??? work. ideas?
like carl, have doubts utility of well, here goes nothing (note i'm typing on phone, syntax associated types may wrong):
{-# language typefamilies #-} class queryable (d :: * -> *) type key type m fetch :: d v -> key -> m v insert :: d v -> key -> v -> m v delete :: d v -> key -> m () now can instantiate class using functor:
instance queryable iointdict type key iointdict = int type m = io ... for pure stuff, use data.functor.identity functor, or maybe use identity type family (i'm not sure approach work out better).
Comments
Post a Comment