# HG changeset patch # User wenzelm # Date 1618059363 -7200 # Node ID 08bef311d3825f79f71a266f166f6ce51e01d559 # Parent 53c148e398199b598d405f2218078f86ceb41ec1 more documentation; diff -r 53c148e39819 -r 08bef311d382 lib/texinputs/isabellesym.sty --- a/lib/texinputs/isabellesym.sty Sat Apr 10 14:55:50 2021 +0200 +++ b/lib/texinputs/isabellesym.sty Sat Apr 10 14:56:03 2021 +0200 @@ -424,6 +424,8 @@ \newcommand{\isasymcheckmark}{\isatext{\ding{51}}} %requires pifont \newcommand{\isasymcrossmark}{\isatext{\ding{55}}} %requires pifont \newcommand{\isactrlmarker}{\isatext{\ding{48}}} %requires pifont +\newcommand{\isactrltry}{\isakeywordcontrol{try}} +\newcommand{\isactrlcan}{\isakeywordcontrol{can}} \newcommand{\isactrlassert}{\isakeywordcontrol{assert}} \newcommand{\isactrlcancel}{\isakeywordcontrol{cancel}} \newcommand{\isactrlbinding}{\isakeywordcontrol{binding}} diff -r 53c148e39819 -r 08bef311d382 src/Doc/Implementation/ML.thy --- a/src/Doc/Implementation/ML.thy Sat Apr 10 14:55:50 2021 +0200 +++ b/src/Doc/Implementation/ML.thy Sat Apr 10 14:56:03 2021 +0200 @@ -1149,6 +1149,10 @@ @{index_ML Runtime.exn_trace: "(unit -> 'a) -> 'a"} \\ \end{mldecls} + \<^rail>\ + (@@{ML_antiquotation try} | @@{ML_antiquotation can}) embedded + \ + \<^descr> \<^ML>\try\~\f x\ makes the partiality of evaluating \f x\ explicit via the option datatype. Interrupts are \<^emph>\not\ handled here, i.e.\ this form serves as safe replacement for the \<^emph>\unsafe\ version \<^ML_text>\(SOME\~\f @@ -1180,18 +1184,38 @@ text %mlantiq \ \begin{matharray}{rcl} + @{ML_antiquotation_def "try"} & : & \ML_antiquotation\ \\ + @{ML_antiquotation_def "can"} & : & \ML_antiquotation\ \\ @{ML_antiquotation_def "assert"} & : & \ML_antiquotation\ \\ @{ML_antiquotation_def "undefined"} & : & \ML_antiquotation\ \\ \end{matharray} - \<^descr> \@{assert}\ inlines a function \<^ML_type>\bool -> unit\ that raises \<^ML>\Fail\ if the argument is \<^ML>\false\. Due to inlining the source position of - failed assertions is included in the error output. + \<^descr> \@{try}\ and \{can}\ are similar to the corresponding functions, but the + argument is taken directly as ML expression: functional abstraction and + application is done implicitly. + + \<^descr> \@{assert}\ inlines a function \<^ML_type>\bool -> unit\ that raises + \<^ML>\Fail\ if the argument is \<^ML>\false\. Due to inlining the source + position of failed assertions is included in the error output. \<^descr> \@{undefined}\ inlines \<^verbatim>\raise\~\<^ML>\Match\, i.e.\ the ML program behaves as in some function application of an undefined case. \ text %mlex \ + We define a total version of division: any failures are swept under the + carpet and mapped to a default value. Thus division-by-zero becomes 0, but + there could be other exceptions like overflow that produce the same result + (for unbounded integers this does not happen). +\ + +ML \ + fun div_total x y = \<^try>\x div y\ |> the_default 0; + + \<^assert> (div_total 1 0 = 0); +\ + +text \ The ML function \<^ML>\undefined\ is defined in \<^file>\~~/src/Pure/library.ML\ as follows: \ @@ -1215,7 +1239,7 @@ ML \fun undefined _ = \<^undefined>\ text \ - \medskip Semantically, all forms are equivalent to a function definition + \<^medskip> Semantically, all forms are equivalent to a function definition without any clauses, but that is syntactically not allowed in ML. \