ghci4luatex-0.0: A GHCi session in LaTeX
Copyright(c) Alice Rixte 2024
LicenseBSD 3
Maintaineralice.rixte@u-bordeaux.fr
Stabilityunstable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Documentation

data SessionMemoizer k a b Source #

A container of memoizers for sequences of commands.

  • k is the key representing the name of a session
  • a is the type of commands
  • b is the result of a command

Constructors

SessionMemoizer 

Fields

Instances

Instances details
(Show a, Show b, Show k) => Show (SessionMemoizer k a b) Source # 
Instance details

Defined in Data.Memoizer.Sessions

(Eq a, Eq b, Eq k) => Eq (SessionMemoizer k a b) Source # 
Instance details

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 restarted.

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 newSession is used.

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 newSession is used.

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.