# HG changeset patch # User wenzelm # Date 1412709078 -7200 # Node ID 4257a7f2bf397cc5d48969e951cc9c0ee71daa73 # Parent c38d8f139bbcc4302949cbf785f21ff981a0ed34 more cartouches; diff -r c38d8f139bbc -r 4257a7f2bf39 src/HOL/ex/ML.thy --- a/src/HOL/ex/ML.thy Tue Oct 07 21:01:31 2014 +0200 +++ b/src/HOL/ex/ML.thy Tue Oct 07 21:11:18 2014 +0200 @@ -2,15 +2,15 @@ Author: Makarius *) -header {* Isabelle/ML basics *} +header \Isabelle/ML basics\ theory "ML" imports Main begin -section {* ML expressions *} +section \ML expressions\ -text {* +text \ The Isabelle command 'ML' allows to embed Isabelle/ML source into the formal text. It is type-checked, compiled, and run within that environment. @@ -18,41 +18,37 @@ global parameters of the run-time environment (rare). ML top-level bindings are managed within the theory context. -*} - -ML {* 1 + 1 *} +\ -ML {* val a = 1 *} -ML {* val b = 1 *} -ML {* val c = a + b *} +ML \1 + 1\ - -section {* Antiquotations *} - -text {* There are some language extensions (via antiquotations), as explained in - the "Isabelle/Isar implementation manual", chapter 0. *} - -ML {* length [] *} -ML {* @{assert} (length [] = 0) *} +ML \val a = 1\ +ML \val b = 1\ +ML \val c = a + b\ -text {* Formal entities from the surrounding context may be referenced as - follows: *} - -term "1 + 1" -- "term within theory source" +section \Antiquotations\ -ML {* - @{term "1 + 1"} (* term as symbolic ML datatype value *) -*} +text \There are some language extensions (via antiquotations), as explained in + the ``Isabelle/Isar implementation manual'', chapter 0.\ -ML {* - @{term "1 + (1::int)"} -*} +ML \length []\ +ML \@{assert} (length [] = 0)\ -section {* IDE support *} +text \Formal entities from the surrounding context may be referenced as + follows:\ + +term "1 + 1" -- \term within theory source\ + +ML \@{term "1 + 1"} (* term as symbolic ML datatype value *)\ -text {* +ML \@{term "1 + (1::int)"}\ + + +section \IDE support\ + +text \ ML embedded into the Isabelle environment is connected to the Prover IDE. Poly/ML provides: \begin{itemize} @@ -60,70 +56,67 @@ \item markup for defining positions of identifiers \item markup for inferred types of sub-expressions \end{itemize} -*} +\ -ML {* fn i => fn list => length list + i *} +ML \fn i => fn list => length list + i\ -section {* Example: factorial and ackermann function in Isabelle/ML *} +section \Example: factorial and ackermann function in Isabelle/ML\ -ML {* +ML \ fun factorial 0 = 1 | factorial n = n * factorial (n - 1) -*} - -ML "factorial 42" -ML "factorial 10000 div factorial 9999" +\ -text {* - See @{url "http://mathworld.wolfram.com/AckermannFunction.html"} -*} +ML \factorial 42\ +ML \factorial 10000 div factorial 9999\ -ML {* +text \See @{url "http://mathworld.wolfram.com/AckermannFunction.html"}\ + +ML \ fun ackermann 0 n = n + 1 | ackermann m 0 = ackermann (m - 1) 1 | ackermann m n = ackermann (m - 1) (ackermann m (n - 1)) -*} +\ -ML {* timeit (fn () => ackermann 3 10) *} +ML \timeit (fn () => ackermann 3 10)\ -section {* Parallel Isabelle/ML *} +section \Parallel Isabelle/ML\ -text {* +text \ Future.fork/join/cancel manage parallel evaluation. Note that within Isabelle theory documents, the top-level command boundary may not be transgressed without special precautions. This is normally managed by - the system when performing parallel proof checking. *} + the system when performing parallel proof checking.\ -ML {* +ML \ val x = Future.fork (fn () => ackermann 3 10); val y = Future.fork (fn () => ackermann 3 10); val z = Future.join x + Future.join y -*} +\ -text {* - The @{ML_structure Par_List} module provides high-level combinators for - parallel list operations. *} +text \The @{ML_structure Par_List} module provides high-level combinators + for parallel list operations.\ -ML {* timeit (fn () => map (fn n => ackermann 3 n) (1 upto 10)) *} -ML {* timeit (fn () => Par_List.map (fn n => ackermann 3 n) (1 upto 10)) *} +ML \timeit (fn () => map (fn n => ackermann 3 n) (1 upto 10))\ +ML \timeit (fn () => Par_List.map (fn n => ackermann 3 n) (1 upto 10))\ -section {* Function specifications in Isabelle/HOL *} +section \Function specifications in Isabelle/HOL\ fun factorial :: "nat \ nat" where "factorial 0 = 1" | "factorial (Suc n) = Suc n * factorial n" -term "factorial 4" -- "symbolic term" -value "factorial 4" -- "evaluation via ML code generation in the background" +term "factorial 4" -- \symbolic term\ +value "factorial 4" -- \evaluation via ML code generation in the background\ declare [[ML_source_trace]] -ML {* @{term "factorial 4"} *} -- "symbolic term in ML" -ML {* @{code "factorial"} *} -- "ML code from function specification" +ML \@{term "factorial 4"}\ -- \symbolic term in ML\ +ML \@{code "factorial"}\ -- \ML code from function specification\ fun ackermann :: "nat \ nat \ nat" diff -r c38d8f139bbc -r 4257a7f2bf39 src/HOL/ex/Seq.thy --- a/src/HOL/ex/Seq.thy Tue Oct 07 21:01:31 2014 +0200 +++ b/src/HOL/ex/Seq.thy Tue Oct 07 21:11:18 2014 +0200 @@ -2,7 +2,7 @@ Author: Makarius *) -header {* Finite sequences *} +header \Finite sequences\ theory Seq imports Main diff -r c38d8f139bbc -r 4257a7f2bf39 src/Tools/SML/Examples.thy --- a/src/Tools/SML/Examples.thy Tue Oct 07 21:01:31 2014 +0200 +++ b/src/Tools/SML/Examples.thy Tue Oct 07 21:11:18 2014 +0200 @@ -2,13 +2,13 @@ Author: Makarius *) -header {* Standard ML within the Isabelle environment *} +header \Standard ML within the Isabelle environment\ theory Examples imports Pure begin -text {* +text \ Isabelle/ML is a somewhat augmented version of Standard ML, with various add-ons that are indispensable for Isabelle development, but may cause conflicts with independent projects in plain Standard ML. @@ -19,34 +19,34 @@ Here is a very basic example that defines the factorial function and evaluates it for some arguments. -*} +\ SML_file "factorial.sml" -text {* +text \ The subsequent example illustrates the use of multiple 'SML_file' commands to build larger Standard ML projects. The toplevel SML environment is enriched cumulatively within the theory context of Isabelle --- independently of the Isabelle/ML environment. -*} +\ SML_file "Example.sig" SML_file "Example.sml" -text {* +text \ Isabelle/ML and SML share a common run-time system, but the static environments are separate. It is possible to exchange toplevel bindings via separate commands like this. -*} +\ -SML_export {* val f = factorial *} -- {* re-use factorial from SML environment *} -ML {* f 42 *} +SML_export \val f = factorial\ -- \re-use factorial from SML environment\ +ML \f 42\ -SML_import {* val println = Output.writeln *} - -- {* re-use Isabelle/ML channel for SML *} +SML_import \val println = Output.writeln\ + -- \re-use Isabelle/ML channel for SML\ -SML_import {* val par_map = Par_List.map *} - -- {* re-use Isabelle/ML parallel list combinator for SML *} +SML_import \val par_map = Par_List.map\ + -- \re-use Isabelle/ML parallel list combinator for SML\ end