test/Tools/isac/ADDTESTS/course/ml_quickstart/ML4_Datastructure.thy
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 15 Jul 2011 10:16:29 +0200
branchdecompose-isar
changeset 42088 74a961375e87
child 59353 a5784cfe30a9
permissions -rw-r--r--
finished ml_quickstart
     1 header {* Quick introduction to ML, session 3 *}
     2 
     3 theory ML4_Datastructure imports Isac begin
     4 
     5 text{* This course follows the book:
     6 J.D.Ullmann, Elements of ML Programming. Prenctice Hall 1998.
     7 Contents:*}
     8 
     9 text {* 
    10   datastructures are tuples and list already introduced, and two further datastructures in ML,
    11   records and "datatypes"
    12 *}
    13 section {* 7.1 Record Structures *}
    14 
    15 ML {*
    16 val wn = {firstname = "Walther", lastname = "Neuper", age = 62, male = true};
    17 val tl = {firstname = "Thomas", lastname = "Leh", age = 17, male = true};
    18 wn = tl;
    19 val {firstname, ...} = tl;
    20 val {firstname = n, ...} = tl;
    21 val {age, ...} = tl;
    22 val {age = tage, ...} = tl;
    23 *}
    24 
    25 section {* 6.2 Datatypes *}
    26 ML {*
    27 infix +++ ***;
    28 datatype formula = 
    29     Num of int
    30   | Var of string
    31   | op +++ of formula * formula
    32   | op *** of formula * formula;
    33 *}
    34 ML {*
    35 (Num 2 *** Num 3) +++ Num 4;
    36 (Num 2 *** Num 3) +++ ((Num 2 *** Num 3) +++ Num 4);
    37 2;
    38 Num 2;
    39 (Num 2 *** Var "x") +++ ((Num 2 *** Num 3) +++ Var "c");
    40 *}
    41 
    42 section {* Preview to Isabelle's terms *}
    43 ML {*
    44 str2term;
    45 str2term "234 * bbb + ccc";
    46 *}
    47 
    48 ML {*
    49 @{term "5"}
    50 *}
    51 end