src/Pure/General/object.ML
author nipkow
Tue, 04 Sep 2001 17:31:18 +0200
changeset 11548 0028bd06a19c
parent 8806 a202293db3f6
child 14981 e73f8140af78
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6118
caa439435666 fixed titles;
wenzelm
parents: 5016
diff changeset
     1
(*  Title:      Pure/General/object.ML
5016
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
8806
wenzelm
parents: 6118
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
5016
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     5
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     6
Generic objects of arbitrary type -- fool the ML type system via
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     7
exception constructors.
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     8
*)
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     9
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    10
signature OBJECT =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    11
sig
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    12
  type T
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    13
  type kind
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    14
  val kind: string -> kind
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    15
  val name_of_kind: kind -> string
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    16
  val eq_kind: kind * kind -> bool
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    17
  val kind_error: kind -> 'a
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    18
end;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    19
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    20
structure Object: OBJECT =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    21
struct
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    22
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    23
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    24
(* anytype values *)
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    25
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    26
type T = exn;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    27
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    28
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    29
(* kinds *)
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    30
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    31
datatype kind = Kind of string * stamp;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    32
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    33
fun kind name = Kind (name, stamp ());
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    34
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    35
fun name_of_kind (Kind (name, _)) = name;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    36
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    37
fun eq_kind (Kind (_, s1), Kind (_, s2)) = s1 = s2;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    38
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    39
fun kind_error k =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    40
  error ("## RUNTIME TYPE ERROR ##\nFailed to access " ^ quote (name_of_kind k) ^ " object");
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    41
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    42
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    43
end;