src/HOL/Unix/Nested_Environment.thy
changeset 44601 04f64e602fa6
parent 44267 d4d48d75aac3
child 44703 f2bfe19239bc
equal deleted inserted replaced
44600:426834f253c8 44601:04f64e602fa6
    41   nested environment).  A \emph{defined position} within a nested
    41   nested environment).  A \emph{defined position} within a nested
    42   environment is one where @{term lookup} at its path does not yield
    42   environment is one where @{term lookup} at its path does not yield
    43   @{term None}.
    43   @{term None}.
    44 *}
    44 *}
    45 
    45 
    46 primrec
    46 primrec lookup :: "('a, 'b, 'c) env => 'c list => ('a, 'b, 'c) env option"
    47   lookup :: "('a, 'b, 'c) env => 'c list => ('a, 'b, 'c) env option"
    47   and lookup_option :: "('a, 'b, 'c) env option => 'c list => ('a, 'b, 'c) env option"
    48   and lookup_option :: "('a, 'b, 'c) env option => 'c list => ('a, 'b, 'c) env option" where
    48 where
    49     "lookup (Val a) xs = (if xs = [] then Some (Val a) else None)"
    49     "lookup (Val a) xs = (if xs = [] then Some (Val a) else None)"
    50   | "lookup (Env b es) xs =
    50   | "lookup (Env b es) xs =
    51       (case xs of
    51       (case xs of
    52         [] => Some (Env b es)
    52         [] => Some (Env b es)
    53       | y # ys => lookup_option (es y) ys)"
    53       | y # ys => lookup_option (es y) ys)"
   243   delete an existing entry, or overwrite an existing one.  Note that
   243   delete an existing entry, or overwrite an existing one.  Note that
   244   update at undefined positions is simple absorbed, i.e.\ the
   244   update at undefined positions is simple absorbed, i.e.\ the
   245   environment is left unchanged.
   245   environment is left unchanged.
   246 *}
   246 *}
   247 
   247 
   248 primrec
   248 primrec update :: "'c list => ('a, 'b, 'c) env option =>
   249   update :: "'c list => ('a, 'b, 'c) env option
   249     ('a, 'b, 'c) env => ('a, 'b, 'c) env"
   250     => ('a, 'b, 'c) env => ('a, 'b, 'c) env"
   250   and update_option :: "'c list => ('a, 'b, 'c) env option =>
   251   and update_option :: "'c list => ('a, 'b, 'c) env option
   251     ('a, 'b, 'c) env option => ('a, 'b, 'c) env option"
   252     => ('a, 'b, 'c) env option => ('a, 'b, 'c) env option" where
   252 where
   253     "update xs opt (Val a) =
   253   "update xs opt (Val a) =
   254       (if xs = [] then (case opt of None => Val a | Some e => e)
   254     (if xs = [] then (case opt of None => Val a | Some e => e)
   255       else Val a)"
   255      else Val a)"
   256   | "update xs opt (Env b es) =
   256 | "update xs opt (Env b es) =
   257       (case xs of
   257     (case xs of
   258         [] => (case opt of None => Env b es | Some e => e)
   258       [] => (case opt of None => Env b es | Some e => e)
   259       | y # ys => Env b (es (y := update_option ys opt (es y))))"
   259     | y # ys => Env b (es (y := update_option ys opt (es y))))"
   260   | "update_option xs opt None =
   260 | "update_option xs opt None =
   261       (if xs = [] then opt else None)"
   261     (if xs = [] then opt else None)"
   262   | "update_option xs opt (Some e) =
   262 | "update_option xs opt (Some e) =
   263       (if xs = [] then opt else Some (update xs opt e))"
   263     (if xs = [] then opt else Some (update xs opt e))"
   264 
   264 
   265 hide_const update_option
   265 hide_const update_option
   266 
   266 
   267 text {*
   267 text {*
   268   \medskip The characteristic cases of @{term update} are expressed by
   268   \medskip The characteristic cases of @{term update} are expressed by