equal
deleted
inserted
replaced
75 swap :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a Heap" |
75 swap :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a Heap" |
76 where |
76 where |
77 "swap i x a = (do |
77 "swap i x a = (do |
78 y \<leftarrow> nth a i; |
78 y \<leftarrow> nth a i; |
79 upd i x a; |
79 upd i x a; |
80 return x |
80 return y |
81 done)" |
81 done)" |
82 |
82 |
83 definition |
83 definition |
84 make :: "nat \<Rightarrow> (nat \<Rightarrow> 'a\<Colon>heap) \<Rightarrow> 'a array Heap" |
84 make :: "nat \<Rightarrow> (nat \<Rightarrow> 'a\<Colon>heap) \<Rightarrow> 'a array Heap" |
85 where |
85 where |
91 "freeze a = (do |
91 "freeze a = (do |
92 n \<leftarrow> length a; |
92 n \<leftarrow> length a; |
93 mapM (nth a) [0..<n] |
93 mapM (nth a) [0..<n] |
94 done)" |
94 done)" |
95 |
95 |
96 definition |
96 hide (open) const new -- {* avoid clashed with some popular names *} |
97 map :: "('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a array \<Rightarrow> 'a array Heap" |
|
98 where |
|
99 "map f a = (do |
|
100 n \<leftarrow> length a; |
|
101 foldM (\<lambda>n. map_entry n f) [0..<n] a |
|
102 done)" |
|
103 |
|
104 hide (open) const new map -- {* avoid clashed with some popular names *} |
|
105 |
97 |
106 |
98 |
107 subsection {* Properties *} |
99 subsection {* Properties *} |
108 |
100 |
109 lemma array_make [code func]: |
101 lemma array_make [code func]: |