113 subsection {* Code generator setup *} |
113 subsection {* Code generator setup *} |
114 |
114 |
115 subsubsection {* Logical intermediate layer *} |
115 subsubsection {* Logical intermediate layer *} |
116 |
116 |
117 definition new' where |
117 definition new' where |
118 [code del]: "new' = Array.new o Code_Index.nat_of" |
118 [code del]: "new' = Array.new o Code_Numeral.nat_of" |
119 hide (open) const new' |
119 hide (open) const new' |
120 lemma [code]: |
120 lemma [code]: |
121 "Array.new = Array.new' o Code_Index.of_nat" |
121 "Array.new = Array.new' o Code_Numeral.of_nat" |
122 by (simp add: new'_def o_def) |
122 by (simp add: new'_def o_def) |
123 |
123 |
124 definition of_list' where |
124 definition of_list' where |
125 [code del]: "of_list' i xs = Array.of_list (take (Code_Index.nat_of i) xs)" |
125 [code del]: "of_list' i xs = Array.of_list (take (Code_Numeral.nat_of i) xs)" |
126 hide (open) const of_list' |
126 hide (open) const of_list' |
127 lemma [code]: |
127 lemma [code]: |
128 "Array.of_list xs = Array.of_list' (Code_Index.of_nat (List.length xs)) xs" |
128 "Array.of_list xs = Array.of_list' (Code_Numeral.of_nat (List.length xs)) xs" |
129 by (simp add: of_list'_def) |
129 by (simp add: of_list'_def) |
130 |
130 |
131 definition make' where |
131 definition make' where |
132 [code del]: "make' i f = Array.make (Code_Index.nat_of i) (f o Code_Index.of_nat)" |
132 [code del]: "make' i f = Array.make (Code_Numeral.nat_of i) (f o Code_Numeral.of_nat)" |
133 hide (open) const make' |
133 hide (open) const make' |
134 lemma [code]: |
134 lemma [code]: |
135 "Array.make n f = Array.make' (Code_Index.of_nat n) (f o Code_Index.nat_of)" |
135 "Array.make n f = Array.make' (Code_Numeral.of_nat n) (f o Code_Numeral.nat_of)" |
136 by (simp add: make'_def o_def) |
136 by (simp add: make'_def o_def) |
137 |
137 |
138 definition length' where |
138 definition length' where |
139 [code del]: "length' = Array.length \<guillemotright>== liftM Code_Index.of_nat" |
139 [code del]: "length' = Array.length \<guillemotright>== liftM Code_Numeral.of_nat" |
140 hide (open) const length' |
140 hide (open) const length' |
141 lemma [code]: |
141 lemma [code]: |
142 "Array.length = Array.length' \<guillemotright>== liftM Code_Index.nat_of" |
142 "Array.length = Array.length' \<guillemotright>== liftM Code_Numeral.nat_of" |
143 by (simp add: length'_def monad_simp', |
143 by (simp add: length'_def monad_simp', |
144 simp add: liftM_def comp_def monad_simp, |
144 simp add: liftM_def comp_def monad_simp, |
145 simp add: monad_simp') |
145 simp add: monad_simp') |
146 |
146 |
147 definition nth' where |
147 definition nth' where |
148 [code del]: "nth' a = Array.nth a o Code_Index.nat_of" |
148 [code del]: "nth' a = Array.nth a o Code_Numeral.nat_of" |
149 hide (open) const nth' |
149 hide (open) const nth' |
150 lemma [code]: |
150 lemma [code]: |
151 "Array.nth a n = Array.nth' a (Code_Index.of_nat n)" |
151 "Array.nth a n = Array.nth' a (Code_Numeral.of_nat n)" |
152 by (simp add: nth'_def) |
152 by (simp add: nth'_def) |
153 |
153 |
154 definition upd' where |
154 definition upd' where |
155 [code del]: "upd' a i x = Array.upd (Code_Index.nat_of i) x a \<guillemotright> return ()" |
155 [code del]: "upd' a i x = Array.upd (Code_Numeral.nat_of i) x a \<guillemotright> return ()" |
156 hide (open) const upd' |
156 hide (open) const upd' |
157 lemma [code]: |
157 lemma [code]: |
158 "Array.upd i x a = Array.upd' a (Code_Index.of_nat i) x \<guillemotright> return a" |
158 "Array.upd i x a = Array.upd' a (Code_Numeral.of_nat i) x \<guillemotright> return a" |
159 by (simp add: upd'_def monad_simp upd_return) |
159 by (simp add: upd'_def monad_simp upd_return) |
160 |
160 |
161 |
161 |
162 subsubsection {* SML *} |
162 subsubsection {* SML *} |
163 |
163 |