325 \verb!@!\verb!{thm_style conclusion hd_Cons_tl}!\\ |
325 \verb!@!\verb!{thm_style conclusion hd_Cons_tl}!\\ |
326 \verb!\end{center}! |
326 \verb!\end{center}! |
327 \end{quote} |
327 \end{quote} |
328 |
328 |
329 If you are not afraid of ML, you may also define your own styles. |
329 If you are not afraid of ML, you may also define your own styles. |
330 A style is simply implemented by an ML function of type \verb!term -> term!. |
330 A style is implemented by an ML function of type |
331 Have a look at the following example (which indeed shows just the way the |
331 \verb!Proof.context -> term -> term!. |
332 \verb!lhs! style is implemented): |
332 Have a look at the following example: |
|
333 |
333 \begin{quote} |
334 \begin{quote} |
334 \verb!setup {!\verb!*!\\ |
335 \verb!setup {!\verb!*!\\ |
335 \verb!let!\\ |
336 \verb!let!\\ |
336 \verb! fun my_lhs (Const ("==", _) $ t $ _) = t!\\ |
337 \verb! fun my_lhs ctxt (Const ("==", _) $ t $ _) = t!\\ |
337 \verb! | my_lhs (Const ("Trueprop", _) $ t) = my_lhs t!\\ |
338 \verb! | my_lhs ctxt (Const ("Trueprop", _) $ t) = my_lhs ctxt t!\\ |
338 \verb! | my_lhs (Const ("==>", _) $ _ $ t) = my_lhs t!\\ |
339 \verb! | my_lhs ctxt (Const ("==>", _) $ _ $ t) = my_lhs ctxt t!\\ |
339 \verb! | my_lhs (_ $ t $ _) = t!\\ |
340 \verb! | my_lhs ctxt (_ $ t $ _) = t!\\ |
340 \verb! | my_lhs _ = error ("Binary operator expected")!\\ |
341 \verb! | my_lhs ctxt _ = error ("Binary operator expected")!\\ |
341 \verb! in [Style.put_style "new_lhs" my_lhs]!\\ |
342 \verb! in [TermStyle.update_style "new_lhs" my_lhs]!\\ |
342 \verb!end;!\\ |
343 \verb!end;!\\ |
343 \verb!*!\verb!}!\\ |
344 \verb!*!\verb!}!\\ |
344 \end{quote} |
345 \end{quote} |
|
346 |
|
347 This example indeed shows a way the \verb!lhs! style could be implemented; |
|
348 note that the real implementation is more sophisticated. |
|
349 |
345 This code must go into your theory file, not as part of your |
350 This code must go into your theory file, not as part of your |
346 \LaTeX\ text but as a separate command in front of it. |
351 \LaTeX\ text but as a separate command in front of it. |
347 Like in this example, it is recommended to put the definition of the style |
352 Like in this example, it is recommended to put the definition of the style |
348 function into a \verb!let! expression, in order not to pollute the |
353 function into a \verb!let! expression, in order not to pollute the |
349 ML global namespace. The mapping from identifier name to the style function |
354 ML global namespace. Each style receives the current proof context |
350 is done by the \verb!Style.put_style! expression which expects the desired |
355 as first argument; this is necessary in situations where the current proof |
351 style name and the style function as arguments. After this \verb!setup!, |
356 context has an impact on the style (which is the case e.~g.~when the |
352 there will be a new style available named \verb!new_lhs! allowing |
357 style has some object-logic specific behaviour). |
|
358 |
|
359 The mapping from identifier name to the style function |
|
360 is done by the \verb!Style.update_style! expression which expects the desired |
|
361 style name and the style function as arguments. |
|
362 |
|
363 After this \verb!setup!, |
|
364 there will be a new style available named \verb!new_lhs!, thus allowing |
353 antiquoations like \verb!@!\verb!{thm_style new_lhs rev_map}! |
365 antiquoations like \verb!@!\verb!{thm_style new_lhs rev_map}! |
354 yielding @{thm_style lhs rev_map}. |
366 yielding @{thm_style lhs rev_map}. |
355 |
367 |
356 The example above may be used as as a ``copy-and-paste'' pattern to write |
368 The example above may be used as as a ``copy-and-paste'' pattern to write |
357 your own styles; for a description of the constructs used, please refer |
369 your own styles; for a description of the constructs used, please refer |
358 to the Isabelle reference manual. |
370 to the Isabelle reference manual. |
359 |
371 |
|
372 |
360 *} |
373 *} |
361 |
374 |
362 (*<*) |
375 (*<*) |
363 end |
376 end |
364 (*>*) |
377 (*>*) |