308 text {* |
308 text {* |
309 \noindent This theorem now is used for generating code: |
309 \noindent This theorem now is used for generating code: |
310 |
310 |
311 \lstsml{Thy/examples/pick1.ML} |
311 \lstsml{Thy/examples/pick1.ML} |
312 |
312 |
313 \noindent It might be convenient to remove the pointless original |
313 \noindent The policy is that \emph{default equations} stemming from |
314 equation, using the \emph{func del} attribute: |
314 @{text "\<DEFINITION>"}, |
315 *} |
315 @{text "\<PRIMREC>"}, @{text "\<FUN>"}, |
316 |
316 @{text "\<FUNCTION>"}, @{text "\<CONSTDEFS>"}, |
317 declare pick.simps [code func del] |
317 @{text "\<RECDEF>"} statements are discarded as soon as an |
318 |
318 equation is explicitly selected by means of \emph{code func}. |
319 export_code pick (*<*)in SML(*>*) in SML file "examples/pick2.ML" |
319 Further applications of \emph{code func} add theorems incrementally, |
320 |
320 but syntactic redundancies are implicitly dropped. For example, |
321 text {* |
|
322 \lstsml{Thy/examples/pick2.ML} |
|
323 |
|
324 \noindent Syntactic redundancies are implicitly dropped. For example, |
|
325 using a modified version of the @{const fac} function |
321 using a modified version of the @{const fac} function |
326 as defining equation, the then redundant (since |
322 as defining equation, the then redundant (since |
327 syntactically subsumed) original defining equations |
323 syntactically subsumed) original defining equations |
328 are dropped, resulting in a warning: |
324 are dropped. |
329 *} |
|
330 |
|
331 lemma [code func]: |
|
332 "fac n = (case n of 0 \<Rightarrow> 1 | Suc m \<Rightarrow> n * fac m)" |
|
333 by (cases n) simp_all |
|
334 |
|
335 export_code fac (*<*)in SML(*>*)in SML file "examples/fac_case.ML" |
|
336 |
|
337 text {* |
|
338 \lstsml{Thy/examples/fac_case.ML} |
|
339 |
325 |
340 \begin{warn} |
326 \begin{warn} |
341 The attributes \emph{code} and \emph{code del} |
327 The attributes \emph{code} and \emph{code del} |
342 associated with the existing code generator also apply to |
328 associated with the existing code generator also apply to |
343 the new one: \emph{code} implies \emph{code func}, |
329 the new one: \emph{code} implies \emph{code func}, |