doc-src/IsarAdvanced/Codegen/Thy/examples/class.ML
author wenzelm
Fri, 19 Jan 2007 22:10:35 +0100
changeset 22124 27b674312b2f
parent 21994 dfa5133dbe73
child 22188 a63889770d57
permissions -rw-r--r--
renamed Isar/isar_output.ML to Thy/thy_output.ML; tuned messages; Antiquote.scan_arguments (moved from here); moved ML context stuff to from Context to ML_Context;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     1
structure ROOT = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     2
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     3
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
     4
structure Nat = 
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     5
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     6
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
     7
datatype nat = Zero_nat | Suc of nat;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     8
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
     9
end; (*struct Nat*)
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    10
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    11
structure Codegen = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    12
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    13
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    14
type 'a null = {null_ : 'a};
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
    15
fun null (A_:'a null) = #null_ A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    16
21994
dfa5133dbe73 updated manual
haftmann
parents: 21993
diff changeset
    17
fun head (A_:'a null) (y :: xs) = y
dfa5133dbe73 updated manual
haftmann
parents: 21993
diff changeset
    18
  | head (A_:'a null) [] = null A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    19
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    20
val null_option : 'b option = NONE;
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    21
21993
4b802a9e0738 updated manual
haftmann
parents: 21190
diff changeset
    22
fun null_optiona () = {null_ = null_option} : ('b option) null ;;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    23
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
    24
val dummy : Nat.nat option =
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
    25
  head (null_optiona ()) [SOME (Nat.Suc Nat.Zero_nat), NONE];
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    26
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    27
end; (*struct Codegen*)
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    28
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    29
end; (*struct ROOT*)