Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize the session type #14

Open
tysonzero opened this issue Sep 9, 2019 · 0 comments
Open

Generalize the session type #14

tysonzero opened this issue Sep 9, 2019 · 0 comments

Comments

@tysonzero
Copy link

tysonzero commented Sep 9, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant