Module HTML.Session

Author
Michael Hanus
Version
October 2025

This module implements the management of sessions. In particular, it defines a cookie that must be sent to the client in order to enable the handling of sessions. Based on sessions, this module also defines a session store that can be used by various parts of the application in order to hold some session-specific data.

Cookies to support sessions


sessionCookie :: IO PageParam  Deterministic 

Creates a cookie to hold the current session id. This cookie should be sent to the client together with every HTML page.

Further infos:
  • might behave indeterministically

doesSessionExist :: IO Bool  Deterministic 

Checks whether the current user session is initialized, i.e., whether a session cookie has been already set.


withSessionCookie :: HtmlPage -> IO HtmlPage  Deterministic 

Decorates an HTML page with a session cookie.

Further infos:
  • might behave indeterministically

withSessionCookieInfo :: HtmlPage -> IO HtmlPage  Deterministic 

Decorates an HTML page with a session cookie and shows an information page when the session cookie is not set.

Further infos:
  • might behave indeterministically

Session data handling


data SessionStore _

The type of a session store which contains data of a particular type. The name of the session store is used to store the session data persistently in files.


sessionStore :: (Read a, Show a) => String -> SessionStore a  Deterministic 

The constructor for a session store containing readable and showable data where a unique store name must be provided. The name is used as a file name in the directory containing all session data.

Further infos:
  • solution complete, i.e., able to compute all solutions

getSessionMaybeData :: (Read a, Show a) => SessionStore a -> FormReader (Maybe a)  Deterministic 

Retrieves session data associates to the current user session. Returns Nothing if there is no data for the current session.

Further infos:
  • might behave indeterministically

getSessionData :: (Read a, Show a) => SessionStore a -> a -> FormReader a  Deterministic 

Retrieves session data associated to the current user session where the second argument is returned if there is no data currently associated to the current session.

Further infos:
  • might behave indeterministically

putSessionData :: (Read a, Show a) => SessionStore a -> a -> IO ()  Deterministic 

Stores session data associated to the current user session in the persistent session store.

Further infos:
  • might behave indeterministically

removeSessionData :: (Read a, Show a) => SessionStore a -> IO ()  Deterministic 

Removes data associated to the current user session from the given session store.

Further infos:
  • might behave indeterministically

modifySessionData :: (Read a, Show a) => SessionStore a -> a -> (a -> a) -> IO ()  Deterministic 

Modifies the session data associated to the current user session according to the update functions provided in the last argument.

Further infos:
  • might behave indeterministically