CookBook/Recipes/StoringData.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 14 Jan 2009 16:46:07 +0000
changeset 68 e7519207c2b7
parent 63 83cea5dc6bac
child 69 19106a9975c1
permissions -rw-r--r--
added more to the "new command section" and tuning

theory StoringData
imports "../Base"
begin

section {* Storing Data\label{recipe:storingdata} *} 


text {*
  {\bf Problem:} 
  Your tool needs to manage data.\smallskip

  {\bf Solution:} This can be achieved using a generic data slot.\smallskip

  Every generic data slot may keep data of any kind which is stored in the
  context.

  *}

ML {* 
local

structure Data = GenericDataFun
 ( type T = int Symtab.table
   val empty = Symtab.empty
   val extend = I
   fun merge _ = Symtab.merge (K true)
 )

in

val lookup = Symtab.lookup o Data.get

fun update k v = Data.map (Symtab.update (k, v))

end *}

setup {* Context.theory_map (update "foo" 1) *}

text {*
 
  @{ML_response [display] "lookup (Context.Proof @{context}) \"foo\"" "SOME 1"} 


*}

text {*
  alternatives: TheoryDataFun, ProofDataFun
  Code: Pure/context.ML *}

end