src/Doc/Codegen/Refinement.thy
changeset 55422 6445a05a1234
parent 53125 f4c6f8f6515b
child 58305 57752a91eec4
equal deleted inserted replaced
55421:0aaca907aeab 55422:6445a05a1234
   146 
   146 
   147 text {*
   147 text {*
   148   \noindent It is good style, although no absolute requirement, to
   148   \noindent It is good style, although no absolute requirement, to
   149   provide code equations for the original artefacts of the implemented
   149   provide code equations for the original artefacts of the implemented
   150   type, if possible; in our case, these are the datatype constructor
   150   type, if possible; in our case, these are the datatype constructor
   151   @{const Queue} and the case combinator @{const queue_case}:
   151   @{const Queue} and the case combinator @{const case_queue}:
   152 *}
   152 *}
   153 
   153 
   154 lemma %quote Queue_AQueue [code]:
   154 lemma %quote Queue_AQueue [code]:
   155   "Queue = AQueue []"
   155   "Queue = AQueue []"
   156   by (simp add: AQueue_def fun_eq_iff)
   156   by (simp add: AQueue_def fun_eq_iff)
   157 
   157 
   158 lemma %quote queue_case_AQueue [code]:
   158 lemma %quote case_queue_AQueue [code]:
   159   "queue_case f (AQueue xs ys) = f (ys @ rev xs)"
   159   "case_queue f (AQueue xs ys) = f (ys @ rev xs)"
   160   by (simp add: AQueue_def)
   160   by (simp add: AQueue_def)
   161 
   161 
   162 text {*
   162 text {*
   163   \noindent The resulting code looks as expected:
   163   \noindent The resulting code looks as expected:
   164 *}
   164 *}
   165 
   165 
   166 text %quotetypewriter {*
   166 text %quotetypewriter {*
   167   @{code_stmts empty enqueue dequeue Queue queue_case (SML)}
   167   @{code_stmts empty enqueue dequeue Queue case_queue (SML)}
   168 *}
   168 *}
   169 
   169 
   170 text {*
   170 text {*
   171   The same techniques can also be applied to types which are not
   171   The same techniques can also be applied to types which are not
   172   specified as datatypes, e.g.~type @{typ int} is originally specified
   172   specified as datatypes, e.g.~type @{typ int} is originally specified
   272   specifies key-value-mappings (type @{typ "('a, 'b) mapping"});
   272   specifies key-value-mappings (type @{typ "('a, 'b) mapping"});
   273   these can be implemented by red-black-trees (theory @{theory RBT}).
   273   these can be implemented by red-black-trees (theory @{theory RBT}).
   274 *}
   274 *}
   275 
   275 
   276 end
   276 end
   277