Knowledge.Context
Context variables.
Context variables could be used to implement stateful analyses. They are not part of the knowledge base per se, but enable convience that is otherwise achieavable through adding a state to the knowledge monad using a monad transformer.
It is important to keep in mind that the contex variables are not a part of the knowledge and that every knowledge computation starts with a fresh set of variables, i.e., variables are not persistent.
The data type of the context variable is not required to have the domain structure or be comparable. The only requirement is that when a variable is declared it should be initialized.
val declare :
?inspect:('a -> Core_kernel.Sexp.t) ->
?package:string ->
string ->
'a knowledge ->
'a var
declare ~package name init
declares a new context variable.
The declared variable has the initial value init
. The inspect
function could be used for debugging and instrospection.
update v f
applies f
to the current value of v
and assigns the result back.