Copyright | (c) Alice Rixte 2024 |
---|---|
License | BSD 3 |
Maintainer | alice.rixte@u-bordeaux.fr |
Stability | unstable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Data.Memoizer.Sessions
Description
Memoize several sessions and switch between them.
This enables the use of the \ghcisection{My Session}
and
\ghcicontinue{My Session}
command in the ghci
LuaTex package.
Usage
Let us store the result of some commands (we alternate between memo
and
memo'
to avoid recursive definitions)
>>>
import Prelude hiding (lookup)
>>>
memo = initSession "main" :: SessionMemoizer String String String
>>>
memo' = storeResult "x=1" "" memo
>>>
memo = storeResult "y=2" "" memo'
>>>
memo' = storeResult "x+y" "3" memo
Let use create a new session:
>>>
memo = newSession "My Session" memo'
>>>
memo' = storeResult "a=1" "" memo
Now if we create a new session called "main" again, we can use the memoized values:
>>>
memo = newSession "main" memo'
>>>
lookup "x=1" memo
Just ""
But we still have some commands to add to "My Session":
>>>
memo' = continueSession "My Session" memo
>>>
memo = storeResult "a" "1" memo'
Now let's restart "My Session":
>>>
memo' = newSession "My Session" memo
>>>
lookup "a=1" memo
Just "">>>
memo = nextCmd memo'
>>>
lookup "a" memo
Just "1"
Synopsis
- data SessionMemoizer k a b = SessionMemoizer {
- sessionMap :: Map k (CmdMemoizer a b)
- currentSession :: k
- initSession :: Ord k => k -> SessionMemoizer k a b
- newSession :: Ord k => k -> SessionMemoizer k a b -> SessionMemoizer k a b
- continueSession :: Ord k => k -> SessionMemoizer k a b -> SessionMemoizer k a b
- storeResult :: Ord k => a -> b -> SessionMemoizer k a b -> SessionMemoizer k a b
- deleteResult :: Ord k => SessionMemoizer k a b -> SessionMemoizer k a b
- lookup :: (Eq a, Ord k) => a -> SessionMemoizer k a b -> Maybe b
- nextCmd :: Ord k => SessionMemoizer k a b -> SessionMemoizer k a b
Documentation
data SessionMemoizer k a b Source #
A container of memoizers for sequences of commands.
k
is the key representing the name of a sessiona
is the type of commandsb
is the result of a command
Constructors
SessionMemoizer | |
Fields
|
Instances
(Show a, Show b, Show k) => Show (SessionMemoizer k a b) Source # | |
Defined in Data.Memoizer.Sessions Methods showsPrec :: Int -> SessionMemoizer k a b -> ShowS # show :: SessionMemoizer k a b -> String # showList :: [SessionMemoizer k a b] -> ShowS # | |
(Eq a, Eq b, Eq k) => Eq (SessionMemoizer k a b) Source # | |
Defined in Data.Memoizer.Sessions Methods (==) :: SessionMemoizer k a b -> SessionMemoizer k a b -> Bool # (/=) :: SessionMemoizer k a b -> SessionMemoizer k a b -> Bool # |
initSession :: Ord k => k -> SessionMemoizer k a b Source #
Create a new session memoizer using a default session.
newSession :: Ord k => k -> SessionMemoizer k a b -> SessionMemoizer k a b Source #
Add a new session to memoize. If that session already existes, it is
ed.restart
continueSession :: Ord k => k -> SessionMemoizer k a b -> SessionMemoizer k a b Source #
Continue an existing session.
storeResult :: Ord k => a -> b -> SessionMemoizer k a b -> SessionMemoizer k a b Source #
Store a result in the current session.
This will prevent access to any memoized result of the current session until
is used.newSession
deleteResult :: Ord k => SessionMemoizer k a b -> SessionMemoizer k a b Source #
Delete the current result in the current session.
This will prevent access to any memoized result of the current session until
is used.newSession
lookup :: (Eq a, Ord k) => a -> SessionMemoizer k a b -> Maybe b Source #
Lookup the memoized result of the current session.
nextCmd :: Ord k => SessionMemoizer k a b -> SessionMemoizer k a b Source #
Move the current session to the next command.