src/HOL/Library/Mapping.thy
changeset 54853 a435932a9f12
parent 53026 e1a548c11845
child 55466 786edc984c98
equal deleted inserted replaced
54852:7137303f9f88 54853:a435932a9f12
   140   by transfer rule
   140   by transfer rule
   141 
   141 
   142 definition map_default :: "'a \<Rightarrow> 'b \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" where
   142 definition map_default :: "'a \<Rightarrow> 'b \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" where
   143   "map_default k v f m = map_entry k f (default k v m)" 
   143   "map_default k v f m = map_entry k f (default k v m)" 
   144 
   144 
   145 lift_definition assoc_list_to_mapping :: "('k \<times> 'v) list \<Rightarrow> ('k, 'v) mapping"
   145 lift_definition of_alist :: "('k \<times> 'v) list \<Rightarrow> ('k, 'v) mapping"
   146 is map_of parametric map_of_transfer .
   146 is map_of parametric map_of_transfer .
   147 
   147 
   148 lemma assoc_list_to_mapping_code [code]:
   148 lemma of_alist_code [code]:
   149   "assoc_list_to_mapping xs = foldr (\<lambda>(k, v) m. update k v m) xs empty"
   149   "of_alist xs = foldr (\<lambda>(k, v) m. update k v m) xs empty"
   150 by transfer(simp add: map_add_map_of_foldr[symmetric])
   150 by transfer(simp add: map_add_map_of_foldr[symmetric])
   151 
   151 
   152 instantiation mapping :: (type, type) equal
   152 instantiation mapping :: (type, type) equal
   153 begin
   153 begin
   154 
   154 
   362 subsection {* Code generator setup *}
   362 subsection {* Code generator setup *}
   363 
   363 
   364 code_datatype empty update
   364 code_datatype empty update
   365 
   365 
   366 hide_const (open) empty is_empty rep lookup update delete ordered_keys keys size
   366 hide_const (open) empty is_empty rep lookup update delete ordered_keys keys size
   367   replace default map_entry map_default tabulate bulkload map
   367   replace default map_entry map_default tabulate bulkload map of_alist
   368 
   368 
   369 end
   369 end
   370 
   370 
   371 
   371