CookBook/Recipes/StoringData.thy
author boehmes
Wed, 07 Jan 2009 16:29:49 +0100
changeset 61 64c9540f2f84
child 63 83cea5dc6bac
permissions -rw-r--r--
Added four recipes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     1
theory StoringData
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     2
imports "../Base"
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     3
begin
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     4
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     5
section {* Storing Data *} 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     6
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     7
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     8
text {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     9
  {\bf Problem:} 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    10
  Your tool needs to keep complex data.\smallskip
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    11
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    12
  {\bf Solution:} This can be achieved using a generic data slot.\smallskip
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    13
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    14
  Every generic data slot may keep data of any kind which is stored in the
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    15
  context.
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    16
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    17
  *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    18
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    19
ML {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    20
local
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    21
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    22
structure Data = GenericDataFun
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    23
(
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    24
  type T = int Symtab.table
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    25
  val empty = Symtab.empty
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    26
  val extend = I
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    27
  fun merge _ = Symtab.merge (K true)
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    28
)
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    29
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    30
in
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    31
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    32
val lookup = Symtab.lookup o Data.get
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    33
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    34
fun update k v = Data.map (Symtab.update (k, v))
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    35
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    36
end
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    37
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    38
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    39
setup {* Context.theory_map (update "foo" 1) *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    40
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    41
ML {* lookup (Context.Proof @{context}) "foo" *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    42
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    43
text {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    44
  alternatives: TheoryDataFun, ProofDataFun
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    45
  Code: Pure/context.ML *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    46
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    47
end