doc-src/Codegen/Thy/document/Adaptation.tex
changeset 39712 94b1890e4e4a
parent 39683 f75a01ee6c41
child 39745 3aa2bc9c5478
equal deleted inserted replaced
39711:793451df8c4e 39712:94b1890e4e4a
   279   additionally, eager evaluation may cause programs to loop or break
   279   additionally, eager evaluation may cause programs to loop or break
   280   which would perfectly terminate when the existing SML \verb|bool| would be used.  To map the HOL \isa{bool} on SML \verb|bool|, we may use \qn{custom serialisations}:%
   280   which would perfectly terminate when the existing SML \verb|bool| would be used.  To map the HOL \isa{bool} on SML \verb|bool|, we may use \qn{custom serialisations}:%
   281 \end{isamarkuptext}%
   281 \end{isamarkuptext}%
   282 \isamarkuptrue%
   282 \isamarkuptrue%
   283 %
   283 %
   284 \isadelimquotett
   284 \isadelimtt
   285 %
   285 %
   286 \endisadelimquotett
   286 \endisadelimtt
   287 %
   287 %
   288 \isatagquotett
   288 \isatagtt
   289 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   289 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   290 \ bool\isanewline
   290 \ bool\isanewline
   291 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}bool{\isachardoublequoteclose}{\isacharparenright}\isanewline
   291 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}bool{\isachardoublequoteclose}{\isacharparenright}\isanewline
   292 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   292 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   293 \ True\ \isakeyword{and}\ False\ \isakeyword{and}\ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
   293 \ True\ \isakeyword{and}\ False\ \isakeyword{and}\ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
   294 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}true{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}false{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}{\isacharunderscore}\ andalso\ {\isacharunderscore}{\isachardoublequoteclose}{\isacharparenright}%
   294 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}true{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}false{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}{\isacharunderscore}\ andalso\ {\isacharunderscore}{\isachardoublequoteclose}{\isacharparenright}%
   295 \endisatagquotett
   295 \endisatagtt
   296 {\isafoldquotett}%
   296 {\isafoldtt}%
   297 %
   297 %
   298 \isadelimquotett
   298 \isadelimtt
   299 %
   299 %
   300 \endisadelimquotett
   300 \endisadelimtt
   301 %
   301 %
   302 \begin{isamarkuptext}%
   302 \begin{isamarkuptext}%
   303 \noindent The \indexdef{}{command}{code\_type}\hypertarget{command.code-type}{\hyperlink{command.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}}} command takes a type constructor
   303 \noindent The \indexdef{}{command}{code\_type}\hypertarget{command.code-type}{\hyperlink{command.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}}} command takes a type constructor
   304   as arguments together with a list of custom serialisations.  Each
   304   as arguments together with a list of custom serialisations.  Each
   305   custom serialisation starts with a target language identifier
   305   custom serialisation starts with a target language identifier
   352   provides some common idioms, notably associative infixes with
   352   provides some common idioms, notably associative infixes with
   353   precedences which may be used here:%
   353   precedences which may be used here:%
   354 \end{isamarkuptext}%
   354 \end{isamarkuptext}%
   355 \isamarkuptrue%
   355 \isamarkuptrue%
   356 %
   356 %
   357 \isadelimquotett
   357 \isadelimtt
   358 %
   358 %
   359 \endisadelimquotett
   359 \endisadelimtt
   360 %
   360 %
   361 \isatagquotett
   361 \isatagtt
   362 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   362 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   363 \ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
   363 \ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
   364 \ \ {\isacharparenleft}SML\ \isakeyword{infixl}\ {\isadigit{1}}\ {\isachardoublequoteopen}andalso{\isachardoublequoteclose}{\isacharparenright}%
   364 \ \ {\isacharparenleft}SML\ \isakeyword{infixl}\ {\isadigit{1}}\ {\isachardoublequoteopen}andalso{\isachardoublequoteclose}{\isacharparenright}%
   365 \endisatagquotett
   365 \endisatagtt
   366 {\isafoldquotett}%
   366 {\isafoldtt}%
   367 %
   367 %
   368 \isadelimquotett
   368 \isadelimtt
   369 %
   369 %
   370 \endisadelimquotett
   370 \endisadelimtt
   371 %
   371 %
   372 \isadelimtypewriter
   372 \isadelimtypewriter
   373 %
   373 %
   374 \endisadelimtypewriter
   374 \endisadelimtypewriter
   375 %
   375 %
   445 %
   445 %
   446 \isadeliminvisible
   446 \isadeliminvisible
   447 %
   447 %
   448 \endisadeliminvisible
   448 \endisadeliminvisible
   449 %
   449 %
   450 \isadelimquotett
   450 \isadelimtt
   451 %
   451 %
   452 \endisadelimquotett
   452 \endisadelimtt
   453 %
   453 %
   454 \isatagquotett
   454 \isatagtt
   455 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   455 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   456 \ prod\isanewline
   456 \ prod\isanewline
   457 \ \ {\isacharparenleft}SML\ \isakeyword{infix}\ {\isadigit{2}}\ {\isachardoublequoteopen}{\isacharasterisk}{\isachardoublequoteclose}{\isacharparenright}\isanewline
   457 \ \ {\isacharparenleft}SML\ \isakeyword{infix}\ {\isadigit{2}}\ {\isachardoublequoteopen}{\isacharasterisk}{\isachardoublequoteclose}{\isacharparenright}\isanewline
   458 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   458 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   459 \ Pair\isanewline
   459 \ Pair\isanewline
   460 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}{\isacharbang}{\isacharparenleft}{\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharcomma}{\isacharslash}\ {\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}%
   460 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}{\isacharbang}{\isacharparenleft}{\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharcomma}{\isacharslash}\ {\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}%
   461 \endisatagquotett
   461 \endisatagtt
   462 {\isafoldquotett}%
   462 {\isafoldtt}%
   463 %
   463 %
   464 \isadelimquotett
   464 \isadelimtt
   465 %
   465 %
   466 \endisadelimquotett
   466 \endisadelimtt
   467 %
   467 %
   468 \begin{isamarkuptext}%
   468 \begin{isamarkuptext}%
   469 \noindent The initial bang ``\verb|!|'' tells the serialiser
   469 \noindent The initial bang ``\verb|!|'' tells the serialiser
   470   never to put parentheses around the whole expression (they are
   470   never to put parentheses around the whole expression (they are
   471   already present), while the parentheses around argument place
   471   already present), while the parentheses around argument place
   497   giving custom serialisations for the class \isa{equal} (by command
   497   giving custom serialisations for the class \isa{equal} (by command
   498   \indexdef{}{command}{code\_class}\hypertarget{command.code-class}{\hyperlink{command.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}}}) and its operation \isa{HOL{\isachardot}equal}%
   498   \indexdef{}{command}{code\_class}\hypertarget{command.code-class}{\hyperlink{command.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}}}) and its operation \isa{HOL{\isachardot}equal}%
   499 \end{isamarkuptext}%
   499 \end{isamarkuptext}%
   500 \isamarkuptrue%
   500 \isamarkuptrue%
   501 %
   501 %
   502 \isadelimquotett
   502 \isadelimtt
   503 %
   503 %
   504 \endisadelimquotett
   504 \endisadelimtt
   505 %
   505 %
   506 \isatagquotett
   506 \isatagtt
   507 \isacommand{code{\isacharunderscore}class}\isamarkupfalse%
   507 \isacommand{code{\isacharunderscore}class}\isamarkupfalse%
   508 \ equal\isanewline
   508 \ equal\isanewline
   509 \ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Eq{\isachardoublequoteclose}{\isacharparenright}\isanewline
   509 \ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Eq{\isachardoublequoteclose}{\isacharparenright}\isanewline
   510 \isanewline
   510 \isanewline
   511 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   511 \isacommand{code{\isacharunderscore}const}\isamarkupfalse%
   512 \ {\isachardoublequoteopen}HOL{\isachardot}equal{\isachardoublequoteclose}\isanewline
   512 \ {\isachardoublequoteopen}HOL{\isachardot}equal{\isachardoublequoteclose}\isanewline
   513 \ \ {\isacharparenleft}Haskell\ \isakeyword{infixl}\ {\isadigit{4}}\ {\isachardoublequoteopen}{\isacharequal}{\isacharequal}{\isachardoublequoteclose}{\isacharparenright}%
   513 \ \ {\isacharparenleft}Haskell\ \isakeyword{infixl}\ {\isadigit{4}}\ {\isachardoublequoteopen}{\isacharequal}{\isacharequal}{\isachardoublequoteclose}{\isacharparenright}%
   514 \endisatagquotett
   514 \endisatagtt
   515 {\isafoldquotett}%
   515 {\isafoldtt}%
   516 %
   516 %
   517 \isadelimquotett
   517 \isadelimtt
   518 %
   518 %
   519 \endisadelimquotett
   519 \endisadelimtt
   520 %
   520 %
   521 \begin{isamarkuptext}%
   521 \begin{isamarkuptext}%
   522 \noindent A problem now occurs whenever a type which is an instance
   522 \noindent A problem now occurs whenever a type which is an instance
   523   of \isa{equal} in \isa{HOL} is mapped on a \isa{Haskell}-built-in type which is also an instance of \isa{Haskell}
   523   of \isa{equal} in \isa{HOL} is mapped on a \isa{Haskell}-built-in type which is also an instance of \isa{Haskell}
   524   \isa{Eq}:%
   524   \isa{Eq}:%
   551 %
   551 %
   552 \isadelimquote
   552 \isadelimquote
   553 %
   553 %
   554 \endisadelimquote
   554 \endisadelimquote
   555 %
   555 %
   556 \isadelimquotett
   556 \isadelimtt
   557 \ %
   557 \ %
   558 \endisadelimquotett
   558 \endisadelimtt
   559 %
   559 %
   560 \isatagquotett
   560 \isatagtt
   561 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   561 \isacommand{code{\isacharunderscore}type}\isamarkupfalse%
   562 \ bar\isanewline
   562 \ bar\isanewline
   563 \ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Integer{\isachardoublequoteclose}{\isacharparenright}%
   563 \ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Integer{\isachardoublequoteclose}{\isacharparenright}%
   564 \endisatagquotett
   564 \endisatagtt
   565 {\isafoldquotett}%
   565 {\isafoldtt}%
   566 %
   566 %
   567 \isadelimquotett
   567 \isadelimtt
   568 %
   568 %
   569 \endisadelimquotett
   569 \endisadelimtt
   570 %
   570 %
   571 \begin{isamarkuptext}%
   571 \begin{isamarkuptext}%
   572 \noindent The code generator would produce an additional instance,
   572 \noindent The code generator would produce an additional instance,
   573   which of course is rejected by the \isa{Haskell} compiler.  To
   573   which of course is rejected by the \isa{Haskell} compiler.  To
   574   suppress this additional instance, use \indexdef{}{command}{code\_instance}\hypertarget{command.code-instance}{\hyperlink{command.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}}}:%
   574   suppress this additional instance, use \indexdef{}{command}{code\_instance}\hypertarget{command.code-instance}{\hyperlink{command.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}}}:%
   575 \end{isamarkuptext}%
   575 \end{isamarkuptext}%
   576 \isamarkuptrue%
   576 \isamarkuptrue%
   577 %
   577 %
   578 \isadelimquotett
   578 \isadelimtt
   579 %
   579 %
   580 \endisadelimquotett
   580 \endisadelimtt
   581 %
   581 %
   582 \isatagquotett
   582 \isatagtt
   583 \isacommand{code{\isacharunderscore}instance}\isamarkupfalse%
   583 \isacommand{code{\isacharunderscore}instance}\isamarkupfalse%
   584 \ bar\ {\isacharcolon}{\isacharcolon}\ equal\isanewline
   584 \ bar\ {\isacharcolon}{\isacharcolon}\ equal\isanewline
   585 \ \ {\isacharparenleft}Haskell\ {\isacharminus}{\isacharparenright}%
   585 \ \ {\isacharparenleft}Haskell\ {\isacharminus}{\isacharparenright}%
   586 \endisatagquotett
   586 \endisatagtt
   587 {\isafoldquotett}%
   587 {\isafoldtt}%
   588 %
   588 %
   589 \isadelimquotett
   589 \isadelimtt
   590 %
   590 %
   591 \endisadelimquotett
   591 \endisadelimtt
   592 %
   592 %
   593 \isamarkupsubsection{Enhancing the target language context \label{sec:include}%
   593 \isamarkupsubsection{Enhancing the target language context \label{sec:include}%
   594 }
   594 }
   595 \isamarkuptrue%
   595 \isamarkuptrue%
   596 %
   596 %
   598 In rare cases it is necessary to \emph{enrich} the context of a
   598 In rare cases it is necessary to \emph{enrich} the context of a
   599   target language; this is accomplished using the \indexdef{}{command}{code\_include}\hypertarget{command.code-include}{\hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}}} command:%
   599   target language; this is accomplished using the \indexdef{}{command}{code\_include}\hypertarget{command.code-include}{\hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}}} command:%
   600 \end{isamarkuptext}%
   600 \end{isamarkuptext}%
   601 \isamarkuptrue%
   601 \isamarkuptrue%
   602 %
   602 %
   603 \isadelimquotett
   603 \isadelimtt
   604 %
   604 %
   605 \endisadelimquotett
   605 \endisadelimtt
   606 %
   606 %
   607 \isatagquotett
   607 \isatagtt
   608 \isacommand{code{\isacharunderscore}include}\isamarkupfalse%
   608 \isacommand{code{\isacharunderscore}include}\isamarkupfalse%
   609 \ Haskell\ {\isachardoublequoteopen}Errno{\isachardoublequoteclose}\isanewline
   609 \ Haskell\ {\isachardoublequoteopen}Errno{\isachardoublequoteclose}\isanewline
   610 {\isacharverbatimopen}errno\ i\ {\isacharequal}\ error\ {\isacharparenleft}{\isachardoublequote}Error\ number{\isacharcolon}\ {\isachardoublequote}\ {\isacharplus}{\isacharplus}\ show\ i{\isacharparenright}{\isacharverbatimclose}\isanewline
   610 {\isacharverbatimopen}errno\ i\ {\isacharequal}\ error\ {\isacharparenleft}{\isachardoublequote}Error\ number{\isacharcolon}\ {\isachardoublequote}\ {\isacharplus}{\isacharplus}\ show\ i{\isacharparenright}{\isacharverbatimclose}\isanewline
   611 \isanewline
   611 \isanewline
   612 \isacommand{code{\isacharunderscore}reserved}\isamarkupfalse%
   612 \isacommand{code{\isacharunderscore}reserved}\isamarkupfalse%
   613 \ Haskell\ Errno%
   613 \ Haskell\ Errno%
   614 \endisatagquotett
   614 \endisatagtt
   615 {\isafoldquotett}%
   615 {\isafoldtt}%
   616 %
   616 %
   617 \isadelimquotett
   617 \isadelimtt
   618 %
   618 %
   619 \endisadelimquotett
   619 \endisadelimtt
   620 %
   620 %
   621 \begin{isamarkuptext}%
   621 \begin{isamarkuptext}%
   622 \noindent Such named \isa{include}s are then prepended to every
   622 \noindent Such named \isa{include}s are then prepended to every
   623   generated code.  Inspect such code in order to find out how
   623   generated code.  Inspect such code in order to find out how
   624   \hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} behaves with respect to a particular
   624   \hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} behaves with respect to a particular