| author | wenzelm | 
| Thu, 29 Jun 2017 21:43:55 +0200 | |
| changeset 66223 | a6fdb22b0ce2 | 
| parent 66148 | 5e60c2d0a1f1 | 
| child 66453 | cc19f7ca2ed6 | 
| permissions | -rw-r--r-- | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 1 | (* Title: HOL/Imperative_HOL/Heap_Monad.thy | 
| 26170 | 2 | Author: John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen | 
| 3 | *) | |
| 4 | ||
| 63167 | 5 | section \<open>A monad with a polymorphic heap and primitive reasoning infrastructure\<close> | 
| 26170 | 6 | |
| 7 | theory Heap_Monad | |
| 41413 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40671diff
changeset | 8 | imports | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40671diff
changeset | 9 | Heap | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40671diff
changeset | 10 | "~~/src/HOL/Library/Monad_Syntax" | 
| 26170 | 11 | begin | 
| 12 | ||
| 63167 | 13 | subsection \<open>The monad\<close> | 
| 26170 | 14 | |
| 63167 | 15 | subsubsection \<open>Monad construction\<close> | 
| 26170 | 16 | |
| 63167 | 17 | text \<open>Monadic heap actions either produce values | 
| 18 | and transform the heap, or fail\<close> | |
| 58310 | 19 | datatype 'a Heap = Heap "heap \<Rightarrow> ('a \<times> heap) option"
 | 
| 26170 | 20 | |
| 66148 | 21 | declare [[code drop: "Code_Evaluation.term_of :: 'a::typerep Heap \<Rightarrow> Code_Evaluation.term"]] | 
| 40266 
d72f1f734e5a
remove term_of equations for Heap type explicitly
 haftmann parents: 
40173diff
changeset | 22 | |
| 37709 | 23 | primrec execute :: "'a Heap \<Rightarrow> heap \<Rightarrow> ('a \<times> heap) option" where
 | 
| 24 | [code del]: "execute (Heap f) = f" | |
| 26170 | 25 | |
| 37758 | 26 | lemma Heap_cases [case_names succeed fail]: | 
| 27 | fixes f and h | |
| 28 | assumes succeed: "\<And>x h'. execute f h = Some (x, h') \<Longrightarrow> P" | |
| 29 | assumes fail: "execute f h = None \<Longrightarrow> P" | |
| 30 | shows P | |
| 31 | using assms by (cases "execute f h") auto | |
| 32 | ||
| 26170 | 33 | lemma Heap_execute [simp]: | 
| 34 | "Heap (execute f) = f" by (cases f) simp_all | |
| 35 | ||
| 36 | lemma Heap_eqI: | |
| 37 | "(\<And>h. execute f h = execute g h) \<Longrightarrow> f = g" | |
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39250diff
changeset | 38 | by (cases f, cases g) (auto simp: fun_eq_iff) | 
| 26170 | 39 | |
| 57956 | 40 | named_theorems execute_simps "simplification rules for execute" | 
| 37758 | 41 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 42 | lemma execute_Let [execute_simps]: | 
| 37758 | 43 | "execute (let x = t in f x) = (let x = t in execute (f x))" | 
| 44 | by (simp add: Let_def) | |
| 45 | ||
| 46 | ||
| 63167 | 47 | subsubsection \<open>Specialised lifters\<close> | 
| 37758 | 48 | |
| 49 | definition tap :: "(heap \<Rightarrow> 'a) \<Rightarrow> 'a Heap" where | |
| 50 | [code del]: "tap f = Heap (\<lambda>h. Some (f h, h))" | |
| 51 | ||
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 52 | lemma execute_tap [execute_simps]: | 
| 37758 | 53 | "execute (tap f) h = Some (f h, h)" | 
| 54 | by (simp add: tap_def) | |
| 26170 | 55 | |
| 37709 | 56 | definition heap :: "(heap \<Rightarrow> 'a \<times> heap) \<Rightarrow> 'a Heap" where | 
| 57 | [code del]: "heap f = Heap (Some \<circ> f)" | |
| 26170 | 58 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 59 | lemma execute_heap [execute_simps]: | 
| 37709 | 60 | "execute (heap f) = Some \<circ> f" | 
| 26170 | 61 | by (simp add: heap_def) | 
| 62 | ||
| 37754 | 63 | definition guard :: "(heap \<Rightarrow> bool) \<Rightarrow> (heap \<Rightarrow> 'a \<times> heap) \<Rightarrow> 'a Heap" where | 
| 64 | [code del]: "guard P f = Heap (\<lambda>h. if P h then Some (f h) else None)" | |
| 65 | ||
| 37758 | 66 | lemma execute_guard [execute_simps]: | 
| 37754 | 67 | "\<not> P h \<Longrightarrow> execute (guard P f) h = None" | 
| 68 | "P h \<Longrightarrow> execute (guard P f) h = Some (f h)" | |
| 69 | by (simp_all add: guard_def) | |
| 70 | ||
| 37758 | 71 | |
| 63167 | 72 | subsubsection \<open>Predicate classifying successful computations\<close> | 
| 37758 | 73 | |
| 74 | definition success :: "'a Heap \<Rightarrow> heap \<Rightarrow> bool" where | |
| 75 | "success f h \<longleftrightarrow> execute f h \<noteq> None" | |
| 76 | ||
| 77 | lemma successI: | |
| 78 | "execute f h \<noteq> None \<Longrightarrow> success f h" | |
| 79 | by (simp add: success_def) | |
| 80 | ||
| 81 | lemma successE: | |
| 82 | assumes "success f h" | |
| 58510 | 83 | obtains r h' where "execute f h = Some (r, h')" | 
| 84 | using assms by (auto simp: success_def) | |
| 37758 | 85 | |
| 57956 | 86 | named_theorems success_intros "introduction rules for success" | 
| 37758 | 87 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 88 | lemma success_tapI [success_intros]: | 
| 37758 | 89 | "success (tap f) h" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 90 | by (rule successI) (simp add: execute_simps) | 
| 37758 | 91 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 92 | lemma success_heapI [success_intros]: | 
| 37758 | 93 | "success (heap f) h" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 94 | by (rule successI) (simp add: execute_simps) | 
| 37758 | 95 | |
| 96 | lemma success_guardI [success_intros]: | |
| 97 | "P h \<Longrightarrow> success (guard P f) h" | |
| 98 | by (rule successI) (simp add: execute_guard) | |
| 99 | ||
| 100 | lemma success_LetI [success_intros]: | |
| 101 | "x = t \<Longrightarrow> success (f x) h \<Longrightarrow> success (let x = t in f x) h" | |
| 102 | by (simp add: Let_def) | |
| 103 | ||
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 104 | lemma success_ifI: | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 105 | "(c \<Longrightarrow> success t h) \<Longrightarrow> (\<not> c \<Longrightarrow> success e h) \<Longrightarrow> | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 106 | success (if c then t else e) h" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 107 | by (simp add: success_def) | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 108 | |
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 109 | |
| 63167 | 110 | subsubsection \<open>Predicate for a simple relational calculus\<close> | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 111 | |
| 63167 | 112 | text \<open> | 
| 113 | The \<open>effect\<close> predicate states that when a computation \<open>c\<close> | |
| 114 | runs with the heap \<open>h\<close> will result in return value \<open>r\<close> | |
| 115 | and a heap \<open>h'\<close>, i.e.~no exception occurs. | |
| 116 | \<close> | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 117 | |
| 40671 | 118 | definition effect :: "'a Heap \<Rightarrow> heap \<Rightarrow> heap \<Rightarrow> 'a \<Rightarrow> bool" where | 
| 119 | effect_def: "effect c h h' r \<longleftrightarrow> execute c h = Some (r, h')" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 120 | |
| 40671 | 121 | lemma effectI: | 
| 122 | "execute c h = Some (r, h') \<Longrightarrow> effect c h h' r" | |
| 123 | by (simp add: effect_def) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 124 | |
| 40671 | 125 | lemma effectE: | 
| 126 | assumes "effect c h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 127 | obtains "r = fst (the (execute c h))" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 128 | and "h' = snd (the (execute c h))" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 129 | and "success c h" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 130 | proof (rule that) | 
| 40671 | 131 | from assms have *: "execute c h = Some (r, h')" by (simp add: effect_def) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 132 | then show "success c h" by (simp add: success_def) | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 133 | from * have "fst (the (execute c h)) = r" and "snd (the (execute c h)) = h'" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 134 | by simp_all | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 135 | then show "r = fst (the (execute c h))" | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 136 | and "h' = snd (the (execute c h))" by simp_all | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 137 | qed | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 138 | |
| 40671 | 139 | lemma effect_success: | 
| 140 | "effect c h h' r \<Longrightarrow> success c h" | |
| 141 | by (simp add: effect_def success_def) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 142 | |
| 40671 | 143 | lemma success_effectE: | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 144 | assumes "success c h" | 
| 40671 | 145 | obtains r h' where "effect c h h' r" | 
| 146 | using assms by (auto simp add: effect_def success_def) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 147 | |
| 40671 | 148 | lemma effect_deterministic: | 
| 149 | assumes "effect f h h' a" | |
| 150 | and "effect f h h'' b" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 151 | shows "a = b" and "h' = h''" | 
| 40671 | 152 | using assms unfolding effect_def by auto | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 153 | |
| 57956 | 154 | named_theorems effect_intros "introduction rules for effect" | 
| 59028 | 155 | and effect_elims "elimination rules for effect" | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 156 | |
| 40671 | 157 | lemma effect_LetI [effect_intros]: | 
| 158 | assumes "x = t" "effect (f x) h h' r" | |
| 159 | shows "effect (let x = t in f x) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 160 | using assms by simp | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 161 | |
| 40671 | 162 | lemma effect_LetE [effect_elims]: | 
| 163 | assumes "effect (let x = t in f x) h h' r" | |
| 164 | obtains "effect (f t) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 165 | using assms by simp | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 166 | |
| 40671 | 167 | lemma effect_ifI: | 
| 168 | assumes "c \<Longrightarrow> effect t h h' r" | |
| 169 | and "\<not> c \<Longrightarrow> effect e h h' r" | |
| 170 | shows "effect (if c then t else e) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 171 | by (cases c) (simp_all add: assms) | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 172 | |
| 40671 | 173 | lemma effect_ifE: | 
| 174 | assumes "effect (if c then t else e) h h' r" | |
| 175 | obtains "c" "effect t h h' r" | |
| 176 | | "\<not> c" "effect e h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 177 | using assms by (cases c) simp_all | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 178 | |
| 40671 | 179 | lemma effect_tapI [effect_intros]: | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 180 | assumes "h' = h" "r = f h" | 
| 40671 | 181 | shows "effect (tap f) h h' r" | 
| 182 | by (rule effectI) (simp add: assms execute_simps) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 183 | |
| 40671 | 184 | lemma effect_tapE [effect_elims]: | 
| 185 | assumes "effect (tap f) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 186 | obtains "h' = h" and "r = f h" | 
| 40671 | 187 | using assms by (rule effectE) (auto simp add: execute_simps) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 188 | |
| 40671 | 189 | lemma effect_heapI [effect_intros]: | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 190 | assumes "h' = snd (f h)" "r = fst (f h)" | 
| 40671 | 191 | shows "effect (heap f) h h' r" | 
| 192 | by (rule effectI) (simp add: assms execute_simps) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 193 | |
| 40671 | 194 | lemma effect_heapE [effect_elims]: | 
| 195 | assumes "effect (heap f) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 196 | obtains "h' = snd (f h)" and "r = fst (f h)" | 
| 40671 | 197 | using assms by (rule effectE) (simp add: execute_simps) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 198 | |
| 40671 | 199 | lemma effect_guardI [effect_intros]: | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 200 | assumes "P h" "h' = snd (f h)" "r = fst (f h)" | 
| 40671 | 201 | shows "effect (guard P f) h h' r" | 
| 202 | by (rule effectI) (simp add: assms execute_simps) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 203 | |
| 40671 | 204 | lemma effect_guardE [effect_elims]: | 
| 205 | assumes "effect (guard P f) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 206 | obtains "h' = snd (f h)" "r = fst (f h)" "P h" | 
| 40671 | 207 | using assms by (rule effectE) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 208 | (auto simp add: execute_simps elim!: successE, cases "P h", auto simp add: execute_simps) | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 209 | |
| 37758 | 210 | |
| 63167 | 211 | subsubsection \<open>Monad combinators\<close> | 
| 26170 | 212 | |
| 37709 | 213 | definition return :: "'a \<Rightarrow> 'a Heap" where | 
| 26170 | 214 | [code del]: "return x = heap (Pair x)" | 
| 215 | ||
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 216 | lemma execute_return [execute_simps]: | 
| 37709 | 217 | "execute (return x) = Some \<circ> Pair x" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 218 | by (simp add: return_def execute_simps) | 
| 26170 | 219 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 220 | lemma success_returnI [success_intros]: | 
| 37758 | 221 | "success (return x) h" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 222 | by (rule successI) (simp add: execute_simps) | 
| 37758 | 223 | |
| 40671 | 224 | lemma effect_returnI [effect_intros]: | 
| 225 | "h = h' \<Longrightarrow> effect (return x) h h' x" | |
| 226 | by (rule effectI) (simp add: execute_simps) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 227 | |
| 40671 | 228 | lemma effect_returnE [effect_elims]: | 
| 229 | assumes "effect (return x) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 230 | obtains "r = x" "h' = h" | 
| 40671 | 231 | using assms by (rule effectE) (simp add: execute_simps) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 232 | |
| 63167 | 233 | definition raise :: "string \<Rightarrow> 'a Heap" where \<comment> \<open>the string is just decoration\<close> | 
| 37709 | 234 | [code del]: "raise s = Heap (\<lambda>_. None)" | 
| 26170 | 235 | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 236 | lemma execute_raise [execute_simps]: | 
| 37709 | 237 | "execute (raise s) = (\<lambda>_. None)" | 
| 26170 | 238 | by (simp add: raise_def) | 
| 239 | ||
| 40671 | 240 | lemma effect_raiseE [effect_elims]: | 
| 241 | assumes "effect (raise x) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 242 | obtains "False" | 
| 40671 | 243 | using assms by (rule effectE) (simp add: success_def execute_simps) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 244 | |
| 37792 | 245 | definition bind :: "'a Heap \<Rightarrow> ('a \<Rightarrow> 'b Heap) \<Rightarrow> 'b Heap" where
 | 
| 246 | [code del]: "bind f g = Heap (\<lambda>h. case execute f h of | |
| 37709 | 247 | Some (x, h') \<Rightarrow> execute (g x) h' | 
| 248 | | None \<Rightarrow> None)" | |
| 249 | ||
| 52622 
e0ff1625e96d
localized and modernized adhoc-overloading (patch by Christian Sternagel);
 wenzelm parents: 
52435diff
changeset | 250 | adhoc_overloading | 
| 
e0ff1625e96d
localized and modernized adhoc-overloading (patch by Christian Sternagel);
 wenzelm parents: 
52435diff
changeset | 251 | Monad_Syntax.bind Heap_Monad.bind | 
| 37792 | 252 | |
| 37758 | 253 | lemma execute_bind [execute_simps]: | 
| 62026 | 254 | "execute f h = Some (x, h') \<Longrightarrow> execute (f \<bind> g) h = execute (g x) h'" | 
| 255 | "execute f h = None \<Longrightarrow> execute (f \<bind> g) h = None" | |
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 256 | by (simp_all add: bind_def) | 
| 37709 | 257 | |
| 38409 | 258 | lemma execute_bind_case: | 
| 62026 | 259 | "execute (f \<bind> g) h = (case (execute f h) of | 
| 38409 | 260 | Some (x, h') \<Rightarrow> execute (g x) h' | None \<Rightarrow> None)" | 
| 261 | by (simp add: bind_def) | |
| 262 | ||
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 263 | lemma execute_bind_success: | 
| 62026 | 264 | "success f h \<Longrightarrow> execute (f \<bind> g) h = execute (g (fst (the (execute f h)))) (snd (the (execute f h)))" | 
| 58510 | 265 | by (cases f h rule: Heap_cases) (auto elim: successE simp add: bind_def) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 266 | |
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 267 | lemma success_bind_executeI: | 
| 62026 | 268 | "execute f h = Some (x, h') \<Longrightarrow> success (g x) h' \<Longrightarrow> success (f \<bind> g) h" | 
| 58510 | 269 | by (auto intro!: successI elim: successE simp add: bind_def) | 
| 37758 | 270 | |
| 40671 | 271 | lemma success_bind_effectI [success_intros]: | 
| 62026 | 272 | "effect f h h' x \<Longrightarrow> success (g x) h' \<Longrightarrow> success (f \<bind> g) h" | 
| 40671 | 273 | by (auto simp add: effect_def success_def bind_def) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 274 | |
| 40671 | 275 | lemma effect_bindI [effect_intros]: | 
| 276 | assumes "effect f h h' r" "effect (g r) h' h'' r'" | |
| 62026 | 277 | shows "effect (f \<bind> g) h h'' r'" | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 278 | using assms | 
| 40671 | 279 | apply (auto intro!: effectI elim!: effectE successE) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 280 | apply (subst execute_bind, simp_all) | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 281 | done | 
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 282 | |
| 40671 | 283 | lemma effect_bindE [effect_elims]: | 
| 62026 | 284 | assumes "effect (f \<bind> g) h h'' r'" | 
| 40671 | 285 | obtains h' r where "effect f h h' r" "effect (g r) h' h'' r'" | 
| 286 | using assms by (auto simp add: effect_def bind_def split: option.split_asm) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 287 | |
| 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 288 | lemma execute_bind_eq_SomeI: | 
| 37878 | 289 | assumes "execute f h = Some (x, h')" | 
| 290 | and "execute (g x) h' = Some (y, h'')" | |
| 62026 | 291 | shows "execute (f \<bind> g) h = Some (y, h'')" | 
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 292 | using assms by (simp add: bind_def) | 
| 37754 | 293 | |
| 62026 | 294 | lemma return_bind [simp]: "return x \<bind> f = f x" | 
| 51485 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 295 | by (rule Heap_eqI) (simp add: execute_simps) | 
| 37709 | 296 | |
| 62026 | 297 | lemma bind_return [simp]: "f \<bind> return = f" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 298 | by (rule Heap_eqI) (simp add: bind_def execute_simps split: option.splits) | 
| 37709 | 299 | |
| 62026 | 300 | lemma bind_bind [simp]: "(f \<bind> g) \<bind> k = (f :: 'a Heap) \<bind> (\<lambda>x. g x \<bind> k)" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 301 | by (rule Heap_eqI) (simp add: bind_def execute_simps split: option.splits) | 
| 37709 | 302 | |
| 62026 | 303 | lemma raise_bind [simp]: "raise e \<bind> f = raise e" | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 304 | by (rule Heap_eqI) (simp add: execute_simps) | 
| 37709 | 305 | |
| 26170 | 306 | |
| 63167 | 307 | subsection \<open>Generic combinators\<close> | 
| 26170 | 308 | |
| 63167 | 309 | subsubsection \<open>Assertions\<close> | 
| 26170 | 310 | |
| 37709 | 311 | definition assert :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a Heap" where
 | 
| 312 | "assert P x = (if P x then return x else raise ''assert'')" | |
| 28742 | 313 | |
| 37758 | 314 | lemma execute_assert [execute_simps]: | 
| 37754 | 315 | "P x \<Longrightarrow> execute (assert P x) h = Some (x, h)" | 
| 316 | "\<not> P x \<Longrightarrow> execute (assert P x) h = None" | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 317 | by (simp_all add: assert_def execute_simps) | 
| 37754 | 318 | |
| 37758 | 319 | lemma success_assertI [success_intros]: | 
| 320 | "P x \<Longrightarrow> success (assert P x) h" | |
| 321 | by (rule successI) (simp add: execute_assert) | |
| 322 | ||
| 40671 | 323 | lemma effect_assertI [effect_intros]: | 
| 324 | "P x \<Longrightarrow> h' = h \<Longrightarrow> r = x \<Longrightarrow> effect (assert P x) h h' r" | |
| 325 | by (rule effectI) (simp add: execute_assert) | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 326 | |
| 40671 | 327 | lemma effect_assertE [effect_elims]: | 
| 328 | assumes "effect (assert P x) h h' r" | |
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 329 | obtains "P x" "r = x" "h' = h" | 
| 40671 | 330 | using assms by (rule effectE) (cases "P x", simp_all add: execute_assert success_def) | 
| 37771 
1bec64044b5e
spelt out relational framework in a consistent way
 haftmann parents: 
37758diff
changeset | 331 | |
| 28742 | 332 | lemma assert_cong [fundef_cong]: | 
| 333 | assumes "P = P'" | |
| 334 | assumes "\<And>x. P' x \<Longrightarrow> f x = f' x" | |
| 62026 | 335 | shows "(assert P x \<bind> f) = (assert P' x \<bind> f')" | 
| 37754 | 336 | by (rule Heap_eqI) (insert assms, simp add: assert_def) | 
| 28742 | 337 | |
| 37758 | 338 | |
| 63167 | 339 | subsubsection \<open>Plain lifting\<close> | 
| 37758 | 340 | |
| 37754 | 341 | definition lift :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b Heap" where
 | 
| 342 | "lift f = return o f" | |
| 37709 | 343 | |
| 37754 | 344 | lemma lift_collapse [simp]: | 
| 345 | "lift f x = return (f x)" | |
| 346 | by (simp add: lift_def) | |
| 37709 | 347 | |
| 37754 | 348 | lemma bind_lift: | 
| 62026 | 349 | "(f \<bind> lift g) = (f \<bind> (\<lambda>x. return (g x)))" | 
| 37754 | 350 | by (simp add: lift_def comp_def) | 
| 37709 | 351 | |
| 37758 | 352 | |
| 63167 | 353 | subsubsection \<open>Iteration -- warning: this is rarely useful!\<close> | 
| 37758 | 354 | |
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 355 | primrec fold_map :: "('a \<Rightarrow> 'b Heap) \<Rightarrow> 'a list \<Rightarrow> 'b list Heap" where
 | 
| 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 356 | "fold_map f [] = return []" | 
| 37792 | 357 | | "fold_map f (x # xs) = do {
 | 
| 37709 | 358 | y \<leftarrow> f x; | 
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 359 | ys \<leftarrow> fold_map f xs; | 
| 37709 | 360 | return (y # ys) | 
| 37792 | 361 | }" | 
| 37709 | 362 | |
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 363 | lemma fold_map_append: | 
| 62026 | 364 | "fold_map f (xs @ ys) = fold_map f xs \<bind> (\<lambda>xs. fold_map f ys \<bind> (\<lambda>ys. return (xs @ ys)))" | 
| 37754 | 365 | by (induct xs) simp_all | 
| 366 | ||
| 37758 | 367 | lemma execute_fold_map_unchanged_heap [execute_simps]: | 
| 37754 | 368 | assumes "\<And>x. x \<in> set xs \<Longrightarrow> \<exists>y. execute (f x) h = Some (y, h)" | 
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 369 | shows "execute (fold_map f xs) h = | 
| 37754 | 370 | Some (List.map (\<lambda>x. fst (the (execute (f x) h))) xs, h)" | 
| 371 | using assms proof (induct xs) | |
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 372 | case Nil show ?case by (simp add: execute_simps) | 
| 37754 | 373 | next | 
| 374 | case (Cons x xs) | |
| 375 | from Cons.prems obtain y | |
| 376 | where y: "execute (f x) h = Some (y, h)" by auto | |
| 37756 
59caa6180fff
avoid slightly odd "M" suffix; rename mapM to fold_map (fold_map_abort would be more correct, though)
 haftmann parents: 
37754diff
changeset | 377 | moreover from Cons.prems Cons.hyps have "execute (fold_map f xs) h = | 
| 37754 | 378 | Some (map (\<lambda>x. fst (the (execute (f x) h))) xs, h)" by auto | 
| 37787 
30dc3abf4a58
theorem collections do not contain default rules any longer
 haftmann parents: 
37772diff
changeset | 379 | ultimately show ?case by (simp, simp only: execute_bind(1), simp add: execute_simps) | 
| 37754 | 380 | qed | 
| 381 | ||
| 40267 | 382 | |
| 63167 | 383 | subsection \<open>Partial function definition setup\<close> | 
| 40267 | 384 | |
| 385 | definition Heap_ord :: "'a Heap \<Rightarrow> 'a Heap \<Rightarrow> bool" where | |
| 386 | "Heap_ord = img_ord execute (fun_ord option_ord)" | |
| 387 | ||
| 44174 
d1d79f0e1ea6
make more HOL theories work with separate set type
 huffman parents: 
43324diff
changeset | 388 | definition Heap_lub :: "'a Heap set \<Rightarrow> 'a Heap" where | 
| 40267 | 389 | "Heap_lub = img_lub execute Heap (fun_lub (flat_lub None))" | 
| 390 | ||
| 54630 
9061af4d5ebc
restrict admissibility to non-empty chains to allow more syntax-directed proof rules
 Andreas Lochbihler parents: 
53361diff
changeset | 391 | lemma Heap_lub_empty: "Heap_lub {} = Heap Map.empty"
 | 
| 
9061af4d5ebc
restrict admissibility to non-empty chains to allow more syntax-directed proof rules
 Andreas Lochbihler parents: 
53361diff
changeset | 392 | by(simp add: Heap_lub_def img_lub_def fun_lub_def flat_lub_def) | 
| 
9061af4d5ebc
restrict admissibility to non-empty chains to allow more syntax-directed proof rules
 Andreas Lochbihler parents: 
53361diff
changeset | 393 | |
| 51485 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 394 | lemma heap_interpretation: "partial_function_definitions Heap_ord Heap_lub" | 
| 40267 | 395 | proof - | 
| 396 | have "partial_function_definitions (fun_ord option_ord) (fun_lub (flat_lub None))" | |
| 397 | by (rule partial_function_lift) (rule flat_interpretation) | |
| 398 | then have "partial_function_definitions (img_ord execute (fun_ord option_ord)) | |
| 399 | (img_lub execute Heap (fun_lub (flat_lub None)))" | |
| 400 | by (rule partial_function_image) (auto intro: Heap_eqI) | |
| 401 | then show "partial_function_definitions Heap_ord Heap_lub" | |
| 402 | by (simp only: Heap_ord_def Heap_lub_def) | |
| 403 | qed | |
| 404 | ||
| 61605 | 405 | interpretation heap: partial_function_definitions Heap_ord Heap_lub | 
| 61566 
c3d6e570ccef
Keyword 'rewrites' identifies rewrite morphisms.
 ballarin parents: 
59104diff
changeset | 406 |   rewrites "Heap_lub {} \<equiv> Heap Map.empty"
 | 
| 54630 
9061af4d5ebc
restrict admissibility to non-empty chains to allow more syntax-directed proof rules
 Andreas Lochbihler parents: 
53361diff
changeset | 407 | by (fact heap_interpretation)(simp add: Heap_lub_empty) | 
| 51485 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 408 | |
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 409 | lemma heap_step_admissible: | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 410 | "option.admissible | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 411 |       (\<lambda>f:: 'a => ('b * 'c) option. \<forall>h h' r. f h = Some (r, h') \<longrightarrow> P x h h' r)"
 | 
| 53361 
1cb7d3c0cf31
move admissible out of class ccpo to avoid unnecessary class predicate in foundational theorems
 Andreas Lochbihler parents: 
52728diff
changeset | 412 | proof (rule ccpo.admissibleI) | 
| 51485 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 413 |   fix A :: "('a \<Rightarrow> ('b * 'c) option) set"
 | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 414 | assume ch: "Complete_Partial_Order.chain option.le_fun A" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 415 | and IH: "\<forall>f\<in>A. \<forall>h h' r. f h = Some (r, h') \<longrightarrow> P x h h' r" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 416 |   from ch have ch': "\<And>x. Complete_Partial_Order.chain option_ord {y. \<exists>f\<in>A. y = f x}" by (rule chain_fun)
 | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 417 | show "\<forall>h h' r. option.lub_fun A h = Some (r, h') \<longrightarrow> P x h h' r" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 418 | proof (intro allI impI) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 419 | fix h h' r assume "option.lub_fun A h = Some (r, h')" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 420 | from flat_lub_in_chain[OF ch' this[unfolded fun_lub_def]] | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 421 |     have "Some (r, h') \<in> {y. \<exists>f\<in>A. y = f h}" by simp
 | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 422 | then have "\<exists>f\<in>A. f h = Some (r, h')" by auto | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 423 | with IH show "P x h h' r" by auto | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 424 | qed | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 425 | qed | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 426 | |
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 427 | lemma admissible_heap: | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 428 | "heap.admissible (\<lambda>f. \<forall>x h h' r. effect (f x) h h' r \<longrightarrow> P x h h' r)" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 429 | proof (rule admissible_fun[OF heap_interpretation]) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 430 | fix x | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 431 | show "ccpo.admissible Heap_lub Heap_ord (\<lambda>a. \<forall>h h' r. effect a h h' r \<longrightarrow> P x h h' r)" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 432 | unfolding Heap_ord_def Heap_lub_def | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 433 | proof (intro admissible_image partial_function_lift flat_interpretation) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 434 | show "option.admissible ((\<lambda>a. \<forall>h h' r. effect a h h' r \<longrightarrow> P x h h' r) \<circ> Heap)" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 435 | unfolding comp_def effect_def execute.simps | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 436 | by (rule heap_step_admissible) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 437 | qed (auto simp add: Heap_eqI) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 438 | qed | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 439 | |
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 440 | lemma fixp_induct_heap: | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 441 | fixes F :: "'c \<Rightarrow> 'c" and | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 442 | U :: "'c \<Rightarrow> 'b \<Rightarrow> 'a Heap" and | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 443 |     C :: "('b \<Rightarrow> 'a Heap) \<Rightarrow> 'c" and
 | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 444 | P :: "'b \<Rightarrow> heap \<Rightarrow> heap \<Rightarrow> 'a \<Rightarrow> bool" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 445 | assumes mono: "\<And>x. monotone (fun_ord Heap_ord) Heap_ord (\<lambda>f. U (F (C f)) x)" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 446 | assumes eq: "f \<equiv> C (ccpo.fixp (fun_lub Heap_lub) (fun_ord Heap_ord) (\<lambda>f. U (F (C f))))" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 447 | assumes inverse2: "\<And>f. U (C f) = f" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 448 | assumes step: "\<And>f x h h' r. (\<And>x h h' r. effect (U f x) h h' r \<Longrightarrow> P x h h' r) | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 449 | \<Longrightarrow> effect (U (F f) x) h h' r \<Longrightarrow> P x h h' r" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 450 | assumes defined: "effect (U f x) h h' r" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 451 | shows "P x h h' r" | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 452 | using step defined heap.fixp_induct_uc[of U F C, OF mono eq inverse2 admissible_heap, of P] | 
| 54630 
9061af4d5ebc
restrict admissibility to non-empty chains to allow more syntax-directed proof rules
 Andreas Lochbihler parents: 
53361diff
changeset | 453 | unfolding effect_def execute.simps | 
| 51485 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 454 | by blast | 
| 
637aa1649ac7
added rudimentary induction rule for partial_function (heap)
 krauss parents: 
51143diff
changeset | 455 | |
| 63167 | 456 | declaration \<open>Partial_Function.init "heap" @{term heap.fixp_fun}
 | 
| 52728 
470b579f35d2
derive specialized version of full fixpoint induction (with admissibility)
 krauss parents: 
52622diff
changeset | 457 |   @{term heap.mono_body} @{thm heap.fixp_rule_uc} @{thm heap.fixp_induct_uc}
 | 
| 63167 | 458 |   (SOME @{thm fixp_induct_heap})\<close>
 | 
| 42949 
618adb3584e5
separate initializations for different modes of partial_function -- generation of induction rules will be non-uniform
 krauss parents: 
41413diff
changeset | 459 | |
| 
618adb3584e5
separate initializations for different modes of partial_function -- generation of induction rules will be non-uniform
 krauss parents: 
41413diff
changeset | 460 | |
| 40267 | 461 | abbreviation "mono_Heap \<equiv> monotone (fun_ord Heap_ord) Heap_ord" | 
| 462 | ||
| 463 | lemma Heap_ordI: | |
| 464 | assumes "\<And>h. execute x h = None \<or> execute x h = execute y h" | |
| 465 | shows "Heap_ord x y" | |
| 466 | using assms unfolding Heap_ord_def img_ord_def fun_ord_def flat_ord_def | |
| 467 | by blast | |
| 468 | ||
| 469 | lemma Heap_ordE: | |
| 470 | assumes "Heap_ord x y" | |
| 471 | obtains "execute x h = None" | "execute x h = execute y h" | |
| 472 | using assms unfolding Heap_ord_def img_ord_def fun_ord_def flat_ord_def | |
| 473 | by atomize_elim blast | |
| 474 | ||
| 46029 
4a19e3d147c3
attribute code_abbrev superseedes code_unfold_post; tuned names and spacing
 haftmann parents: 
45294diff
changeset | 475 | lemma bind_mono [partial_function_mono]: | 
| 40267 | 476 | assumes mf: "mono_Heap B" and mg: "\<And>y. mono_Heap (\<lambda>f. C y f)" | 
| 62026 | 477 | shows "mono_Heap (\<lambda>f. B f \<bind> (\<lambda>y. C y f))" | 
| 40267 | 478 | proof (rule monotoneI) | 
| 479 | fix f g :: "'a \<Rightarrow> 'b Heap" assume fg: "fun_ord Heap_ord f g" | |
| 480 | from mf | |
| 481 | have 1: "Heap_ord (B f) (B g)" by (rule monotoneD) (rule fg) | |
| 482 | from mg | |
| 483 | have 2: "\<And>y'. Heap_ord (C y' f) (C y' g)" by (rule monotoneD) (rule fg) | |
| 484 | ||
| 62026 | 485 | have "Heap_ord (B f \<bind> (\<lambda>y. C y f)) (B g \<bind> (\<lambda>y. C y f))" | 
| 40267 | 486 | (is "Heap_ord ?L ?R") | 
| 487 | proof (rule Heap_ordI) | |
| 488 | fix h | |
| 489 | from 1 show "execute ?L h = None \<or> execute ?L h = execute ?R h" | |
| 490 | by (rule Heap_ordE[where h = h]) (auto simp: execute_bind_case) | |
| 491 | qed | |
| 492 | also | |
| 62026 | 493 | have "Heap_ord (B g \<bind> (\<lambda>y'. C y' f)) (B g \<bind> (\<lambda>y'. C y' g))" | 
| 40267 | 494 | (is "Heap_ord ?L ?R") | 
| 495 | proof (rule Heap_ordI) | |
| 496 | fix h | |
| 497 | show "execute ?L h = None \<or> execute ?L h = execute ?R h" | |
| 498 | proof (cases "execute (B g) h") | |
| 499 | case None | |
| 500 | then have "execute ?L h = None" by (auto simp: execute_bind_case) | |
| 501 | thus ?thesis .. | |
| 502 | next | |
| 503 | case Some | |
| 504 | then obtain r h' where "execute (B g) h = Some (r, h')" | |
| 505 | by (metis surjective_pairing) | |
| 506 | then have "execute ?L h = execute (C r f) h'" | |
| 507 | "execute ?R h = execute (C r g) h'" | |
| 508 | by (auto simp: execute_bind_case) | |
| 509 | with 2[of r] show ?thesis by (auto elim: Heap_ordE) | |
| 510 | qed | |
| 511 | qed | |
| 512 | finally (heap.leq_trans) | |
| 62026 | 513 | show "Heap_ord (B f \<bind> (\<lambda>y. C y f)) (B g \<bind> (\<lambda>y'. C y' g))" . | 
| 40267 | 514 | qed | 
| 515 | ||
| 516 | ||
| 63167 | 517 | subsection \<open>Code generator setup\<close> | 
| 26182 | 518 | |
| 63167 | 519 | subsubsection \<open>Logical intermediate layer\<close> | 
| 26182 | 520 | |
| 39250 
548a3e5521ab
changing String.literal to a type instead of a datatype
 bulwahn parents: 
39198diff
changeset | 521 | definition raise' :: "String.literal \<Rightarrow> 'a Heap" where | 
| 57437 | 522 | [code del]: "raise' s = raise (String.explode s)" | 
| 39250 
548a3e5521ab
changing String.literal to a type instead of a datatype
 bulwahn parents: 
39198diff
changeset | 523 | |
| 46029 
4a19e3d147c3
attribute code_abbrev superseedes code_unfold_post; tuned names and spacing
 haftmann parents: 
45294diff
changeset | 524 | lemma [code_abbrev]: "raise' (STR s) = raise s" | 
| 
4a19e3d147c3
attribute code_abbrev superseedes code_unfold_post; tuned names and spacing
 haftmann parents: 
45294diff
changeset | 525 | unfolding raise'_def by (simp add: STR_inverse) | 
| 26182 | 526 | |
| 46029 
4a19e3d147c3
attribute code_abbrev superseedes code_unfold_post; tuned names and spacing
 haftmann parents: 
45294diff
changeset | 527 | lemma raise_raise': (* FIXME delete candidate *) | 
| 37709 | 528 | "raise s = raise' (STR s)" | 
| 39250 
548a3e5521ab
changing String.literal to a type instead of a datatype
 bulwahn parents: 
39198diff
changeset | 529 | unfolding raise'_def by (simp add: STR_inverse) | 
| 26182 | 530 | |
| 63167 | 531 | code_datatype raise' \<comment> \<open>avoid @{const "Heap"} formally\<close>
 | 
| 26182 | 532 | |
| 533 | ||
| 63167 | 534 | subsubsection \<open>SML and OCaml\<close> | 
| 26182 | 535 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 536 | code_printing type_constructor Heap \<rightharpoonup> (SML) "(unit/ ->/ _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 537 | code_printing constant bind \<rightharpoonup> (SML) "!(fn/ f'_/ =>/ fn/ ()/ =>/ f'_/ (_/ ())/ ())" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 538 | code_printing constant return \<rightharpoonup> (SML) "!(fn/ ()/ =>/ _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 539 | code_printing constant Heap_Monad.raise' \<rightharpoonup> (SML) "!(raise/ Fail/ _)" | 
| 26182 | 540 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 541 | code_printing type_constructor Heap \<rightharpoonup> (OCaml) "(unit/ ->/ _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 542 | code_printing constant bind \<rightharpoonup> (OCaml) "!(fun/ f'_/ ()/ ->/ f'_/ (_/ ())/ ())" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 543 | code_printing constant return \<rightharpoonup> (OCaml) "!(fun/ ()/ ->/ _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 544 | code_printing constant Heap_Monad.raise' \<rightharpoonup> (OCaml) "failwith" | 
| 27707 | 545 | |
| 37838 | 546 | |
| 63167 | 547 | subsubsection \<open>Haskell\<close> | 
| 37838 | 548 | |
| 63167 | 549 | text \<open>Adaption layer\<close> | 
| 37838 | 550 | |
| 55372 | 551 | code_printing code_module "Heap" \<rightharpoonup> (Haskell) | 
| 63167 | 552 | \<open>import qualified Control.Monad; | 
| 37838 | 553 | import qualified Control.Monad.ST; | 
| 554 | import qualified Data.STRef; | |
| 555 | import qualified Data.Array.ST; | |
| 556 | ||
| 557 | type RealWorld = Control.Monad.ST.RealWorld; | |
| 558 | type ST s a = Control.Monad.ST.ST s a; | |
| 559 | type STRef s a = Data.STRef.STRef s a; | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 560 | type STArray s a = Data.Array.ST.STArray s Integer a; | 
| 37838 | 561 | |
| 562 | newSTRef = Data.STRef.newSTRef; | |
| 563 | readSTRef = Data.STRef.readSTRef; | |
| 564 | writeSTRef = Data.STRef.writeSTRef; | |
| 565 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 566 | newArray :: Integer -> a -> ST s (STArray s a); | 
| 58939 
994fe0ba8335
less space-wasting serialization setup: highest cell of array has been unused so far
 haftmann parents: 
58889diff
changeset | 567 | newArray k = Data.Array.ST.newArray (0, k - 1); | 
| 37838 | 568 | |
| 569 | newListArray :: [a] -> ST s (STArray s a); | |
| 58939 
994fe0ba8335
less space-wasting serialization setup: highest cell of array has been unused so far
 haftmann parents: 
58889diff
changeset | 570 | newListArray xs = Data.Array.ST.newListArray (0, (fromInteger . toInteger . length) xs - 1) xs; | 
| 37838 | 571 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 572 | newFunArray :: Integer -> (Integer -> a) -> ST s (STArray s a); | 
| 58939 
994fe0ba8335
less space-wasting serialization setup: highest cell of array has been unused so far
 haftmann parents: 
58889diff
changeset | 573 | newFunArray k f = Data.Array.ST.newListArray (0, k - 1) (map f [0..k-1]); | 
| 37838 | 574 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 575 | lengthArray :: STArray s a -> ST s Integer; | 
| 58939 
994fe0ba8335
less space-wasting serialization setup: highest cell of array has been unused so far
 haftmann parents: 
58889diff
changeset | 576 | lengthArray a = Control.Monad.liftM (\(_, l) -> l + 1) (Data.Array.ST.getBounds a); | 
| 37838 | 577 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 578 | readArray :: STArray s a -> Integer -> ST s a; | 
| 37838 | 579 | readArray = Data.Array.ST.readArray; | 
| 580 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 581 | writeArray :: STArray s a -> Integer -> a -> ST s (); | 
| 63167 | 582 | writeArray = Data.Array.ST.writeArray;\<close> | 
| 37838 | 583 | |
| 584 | code_reserved Haskell Heap | |
| 585 | ||
| 63167 | 586 | text \<open>Monad\<close> | 
| 37838 | 587 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 588 | code_printing type_constructor Heap \<rightharpoonup> (Haskell) "Heap.ST/ Heap.RealWorld/ _" | 
| 37838 | 589 | code_monad bind Haskell | 
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 590 | code_printing constant return \<rightharpoonup> (Haskell) "return" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 591 | code_printing constant Heap_Monad.raise' \<rightharpoonup> (Haskell) "error" | 
| 37838 | 592 | |
| 593 | ||
| 63167 | 594 | subsubsection \<open>Scala\<close> | 
| 37838 | 595 | |
| 55372 | 596 | code_printing code_module "Heap" \<rightharpoonup> (Scala) | 
| 63167 | 597 | \<open>object Heap {
 | 
| 38968 
e55deaa22fff
do not print object frame around Scala includes -- this is in the responsibility of the user
 haftmann parents: 
38773diff
changeset | 598 | def bind[A, B](f: Unit => A, g: A => Unit => B): Unit => B = (_: Unit) => g (f ()) () | 
| 
e55deaa22fff
do not print object frame around Scala includes -- this is in the responsibility of the user
 haftmann parents: 
38773diff
changeset | 599 | } | 
| 37842 | 600 | |
| 601 | class Ref[A](x: A) {
 | |
| 602 | var value = x | |
| 603 | } | |
| 604 | ||
| 605 | object Ref {
 | |
| 38771 | 606 | def apply[A](x: A): Ref[A] = | 
| 607 | new Ref[A](x) | |
| 608 | def lookup[A](r: Ref[A]): A = | |
| 609 | r.value | |
| 610 | def update[A](r: Ref[A], x: A): Unit = | |
| 611 |     { r.value = x }
 | |
| 37842 | 612 | } | 
| 613 | ||
| 37964 | 614 | object Array {
 | 
| 38968 
e55deaa22fff
do not print object frame around Scala includes -- this is in the responsibility of the user
 haftmann parents: 
38773diff
changeset | 615 | import collection.mutable.ArraySeq | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 616 | def alloc[A](n: BigInt)(x: A): ArraySeq[A] = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 617 | ArraySeq.fill(n.toInt)(x) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 618 | def make[A](n: BigInt)(f: BigInt => A): ArraySeq[A] = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 619 | ArraySeq.tabulate(n.toInt)((k: Int) => f(BigInt(k))) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 620 | def len[A](a: ArraySeq[A]): BigInt = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 621 | BigInt(a.length) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 622 | def nth[A](a: ArraySeq[A], n: BigInt): A = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 623 | a(n.toInt) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 624 | def upd[A](a: ArraySeq[A], n: BigInt, x: A): Unit = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48073diff
changeset | 625 | a.update(n.toInt, x) | 
| 38771 | 626 | def freeze[A](a: ArraySeq[A]): List[A] = | 
| 627 | a.toList | |
| 38968 
e55deaa22fff
do not print object frame around Scala includes -- this is in the responsibility of the user
 haftmann parents: 
38773diff
changeset | 628 | } | 
| 63167 | 629 | \<close> | 
| 37842 | 630 | |
| 38968 
e55deaa22fff
do not print object frame around Scala includes -- this is in the responsibility of the user
 haftmann parents: 
38773diff
changeset | 631 | code_reserved Scala Heap Ref Array | 
| 37838 | 632 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 633 | code_printing type_constructor Heap \<rightharpoonup> (Scala) "(Unit/ =>/ _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 634 | code_printing constant bind \<rightharpoonup> (Scala) "Heap.bind" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 635 | code_printing constant return \<rightharpoonup> (Scala) "('_: Unit)/ =>/ _"
 | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52388diff
changeset | 636 | code_printing constant Heap_Monad.raise' \<rightharpoonup> (Scala) "!sys.error((_))" | 
| 37838 | 637 | |
| 638 | ||
| 63167 | 639 | subsubsection \<open>Target variants with less units\<close> | 
| 37838 | 640 | |
| 63167 | 641 | setup \<open> | 
| 31871 | 642 | |
| 643 | let | |
| 27707 | 644 | |
| 31871 | 645 | open Code_Thingol; | 
| 646 | ||
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 647 | val imp_program = | 
| 31871 | 648 | let | 
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 649 |     val is_bind = curry (op =) @{const_name bind};
 | 
| 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 650 |     val is_return = curry (op =) @{const_name return};
 | 
| 31893 | 651 | val dummy_name = ""; | 
| 652 | val dummy_case_term = IVar NONE; | |
| 31871 | 653 | (*assumption: dummy values are not relevant for serialization*) | 
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 654 |     val unitT = @{type_name unit} `%% [];
 | 
| 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 655 | val unitt = | 
| 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 656 |       IConst { sym = Code_Symbol.Constant @{const_name Unity}, typargs = [], dicts = [], dom = [],
 | 
| 58397 | 657 | annotation = NONE }; | 
| 31871 | 658 | fun dest_abs ((v, ty) `|=> t, _) = ((v, ty), t) | 
| 659 | | dest_abs (t, ty) = | |
| 660 | let | |
| 661 | val vs = fold_varnames cons t []; | |
| 43324 
2b47822868e4
discontinued Name.variant to emphasize that this is old-style / indirect;
 wenzelm parents: 
43080diff
changeset | 662 | val v = singleton (Name.variant_list vs) "x"; | 
| 31871 | 663 | val ty' = (hd o fst o unfold_fun) ty; | 
| 31893 | 664 | in ((SOME v, ty'), t `$ IVar (SOME v)) end; | 
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 665 |     fun force (t as IConst { sym = Code_Symbol.Constant c, ... } `$ t') = if is_return c
 | 
| 31871 | 666 | then t' else t `$ unitt | 
| 667 | | force t = t `$ unitt; | |
| 38385 | 668 | fun tr_bind'' [(t1, _), (t2, ty2)] = | 
| 31871 | 669 | let | 
| 670 | val ((v, ty), t) = dest_abs (t2, ty2); | |
| 48072 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 671 |       in ICase { term = force t1, typ = ty, clauses = [(IVar v, tr_bind' t)], primitive = dummy_case_term } end
 | 
| 38385 | 672 | and tr_bind' t = case unfold_app t | 
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 673 |      of (IConst { sym = Code_Symbol.Constant c, dom = ty1 :: ty2 :: _, ... }, [x1, x2]) => if is_bind c
 | 
| 38386 | 674 | then tr_bind'' [(x1, ty1), (x2, ty2)] | 
| 675 | else force t | |
| 676 | | _ => force t; | |
| 48072 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 677 | fun imp_monad_bind'' ts = (SOME dummy_name, unitT) `|=> | 
| 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 678 |       ICase { term = IVar (SOME dummy_name), typ = unitT, clauses = [(unitt, tr_bind'' ts)], primitive = dummy_case_term }
 | 
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 679 |     fun imp_monad_bind' (const as { sym = Code_Symbol.Constant c, dom = dom, ... }) ts = if is_bind c then case (ts, dom)
 | 
| 31871 | 680 | of ([t1, t2], ty1 :: ty2 :: _) => imp_monad_bind'' [(t1, ty1), (t2, ty2)] | 
| 681 | | ([t1, t2, t3], ty1 :: ty2 :: _) => imp_monad_bind'' [(t1, ty1), (t2, ty2)] `$ t3 | |
| 682 | | (ts, _) => imp_monad_bind (eta_expand 2 (const, ts)) | |
| 683 | else IConst const `$$ map imp_monad_bind ts | |
| 684 | and imp_monad_bind (IConst const) = imp_monad_bind' const [] | |
| 685 | | imp_monad_bind (t as IVar _) = t | |
| 686 | | imp_monad_bind (t as _ `$ _) = (case unfold_app t | |
| 687 | of (IConst const, ts) => imp_monad_bind' const ts | |
| 688 | | (t, ts) => imp_monad_bind t `$$ map imp_monad_bind ts) | |
| 689 | | imp_monad_bind (v_ty `|=> t) = v_ty `|=> imp_monad_bind t | |
| 48072 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 690 |       | imp_monad_bind (ICase { term = t, typ = ty, clauses = clauses, primitive = t0 }) =
 | 
| 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 691 |           ICase { term = imp_monad_bind t, typ = ty,
 | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
59028diff
changeset | 692 | clauses = (map o apply2) imp_monad_bind clauses, primitive = imp_monad_bind t0 }; | 
| 28663 
bd8438543bf2
code identifier namings are no longer imperative
 haftmann parents: 
28562diff
changeset | 693 | |
| 55147 
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
 haftmann parents: 
54630diff
changeset | 694 | in (Code_Symbol.Graph.map o K o map_terms_stmt) imp_monad_bind end; | 
| 27707 | 695 | |
| 696 | in | |
| 697 | ||
| 59104 | 698 | Code_Target.add_derived_target ("SML_imp", [("SML", imp_program)])
 | 
| 699 | #> Code_Target.add_derived_target ("OCaml_imp", [("OCaml", imp_program)])
 | |
| 700 | #> Code_Target.add_derived_target ("Scala_imp", [("Scala", imp_program)])
 | |
| 27707 | 701 | |
| 702 | end | |
| 31871 | 703 | |
| 63167 | 704 | \<close> | 
| 27707 | 705 | |
| 37758 | 706 | hide_const (open) Heap heap guard raise' fold_map | 
| 37724 | 707 | |
| 26170 | 708 | end | 
| 48072 
ace701efe203
prefer records with speaking labels over deeply nested tuples
 haftmann parents: 
46029diff
changeset | 709 |