It appears to me as though the internal structure of the Session type is not used in Network.Wai.Session, and thus it could be generalized to support other kinds of sessions.
Specifically it seems as though:
type SessionStore m k v = (Maybe ByteString -> IO (Session m k v, IO ByteString))
type Session m k v = ((k -> m (Maybe v)), (k -> v -> m ()))
Could be replaced with
type SessionStore s = (Maybe ByteString -> IO (Maybe s, IO ByteString))
Then Network.Wai.Session.Map could be adjusted to:
type Session m k v = ((k -> m (Maybe v)), (k -> v -> m ()))
mapStore_ :: (Ord k, MonadIO m) => IO (SessionStore (Session m k v))
The practical reason why I ask for this, is because in my case sessions are simply represented by a UserId and all stateful changes to the session are done via the DB. So the Map-based representation is very awkward.
The reason for Maybe s instead of s, is that due to the nature of Vault, you must always handle the case where nothing was inserted into the key. So you may as well allow wai-session to make use of this, to avoid having to doubly nest Maybe in the case that you want to be able to support a Nothing session.
It appears to me as though the internal structure of the
Sessiontype is not used inNetwork.Wai.Session, and thus it could be generalized to support other kinds of sessions.Specifically it seems as though:
Could be replaced with
Then
Network.Wai.Session.Mapcould be adjusted to:The practical reason why I ask for this, is because in my case sessions are simply represented by a
UserIdand all stateful changes to the session are done via the DB. So the Map-based representation is very awkward.The reason for
Maybe sinstead ofs, is that due to the nature ofVault, you must always handle the case where nothing was inserted into the key. So you may as well allowwai-sessionto make use of this, to avoid having to doubly nestMaybein the case that you want to be able to support aNothingsession.