test/Tools/isac/ADDTESTS/course/ml_quickstart/ML4_Datastructure.thy
author wneuper <Walther.Neuper@jku.at>
Sun, 09 Oct 2022 07:44:22 +0200
changeset 60565 f92963a33fe3
parent 59592 99c8d2ff63eb
permissions -rw-r--r--
eliminate term2str in test/*
     1 (* Quick introduction to ML, session 3 *)
     2 
     3 theory ML4_Datastructure imports Isac.Isac_Knowledge begin
     4 
     5 text\<open>This course follows the book:
     6 J.D.Ullmann, Elements of ML Programming. Prenctice Hall 1998.
     7 Contents:\<close>
     8 
     9 text \<open>
    10   datastructures are tuples and list already introduced, and two further datastructures in ML,
    11   records and "datatypes"
    12 \<close>
    13 section \<open>7.1 Record Structures\<close>
    14 
    15 ML \<open>
    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 \<close>
    24 
    25 section \<open>6.2 Datatypes\<close>
    26 ML \<open>
    27 infix +++ ***;
    28 datatype formula = 
    29     Num of int
    30   | Var of string
    31   | op +++ of formula * formula
    32   | op *** of formula * formula;
    33 \<close>
    34 ML \<open>
    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 \<close>
    41 
    42 section \<open>Preview to Isabelle's terms\<close>
    43 ML \<open>
    44 parse_test @{context};
    45 parse_test @{context} "234 * bbb + ccc";
    46 \<close>
    47 
    48 ML \<open>
    49 @{term "5"}
    50 \<close>
    51 end