doc-src/IsarAdvanced/Codegen/Thy/examples/class.ML
author blanchet
Tue, 17 Feb 2009 14:01:54 +0100
changeset 29956 62f931b257b7
parent 25182 64e3f45dc6f4
permissions -rw-r--r--
Reintroduce set_interpreter for Collect and op :. I removed them by accident when removing old code that dealt with the "set" type. Incidentally, there is still some broken "set" code in Refute that should be fixed (see TODO in refute.ML).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
     1
structure Nat = 
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     2
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     3
24421
acfb2413faa3 updated
haftmann
parents: 23850
diff changeset
     4
datatype nat = Suc of nat | Zero_nat;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     5
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
     6
end; (*struct Nat*)
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     7
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     8
structure Codegen = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     9
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    10
22386
4ebe883b02ff new code theorems
haftmann
parents: 22188
diff changeset
    11
type 'a null = {null : 'a};
4ebe883b02ff new code theorems
haftmann
parents: 22188
diff changeset
    12
fun null (A_:'a null) = #null A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    13
25182
64e3f45dc6f4 updated;
wenzelm
parents: 25056
diff changeset
    14
fun head A_ (x :: xs) = x
64e3f45dc6f4 updated;
wenzelm
parents: 25056
diff changeset
    15
  | head A_ [] = null A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    16
25056
743f3603ba8b updated;
wenzelm
parents: 24628
diff changeset
    17
val null_option : 'a option = NONE;
743f3603ba8b updated;
wenzelm
parents: 24628
diff changeset
    18
743f3603ba8b updated;
wenzelm
parents: 24628
diff changeset
    19
fun null_optiona () = {null = null_option} : ('a option) null;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    20
21190
08ec81dfc7fb (continued)
haftmann
parents: 21147
diff changeset
    21
val dummy : Nat.nat option =
25056
743f3603ba8b updated;
wenzelm
parents: 24628
diff changeset
    22
  head (null_optiona ()) [SOME (Nat.Suc Nat.Zero_nat), NONE];
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    23
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    24
end; (*struct Codegen*)