src/Pure/General/object.ML
author wenzelm
Thu, 07 Apr 2005 09:26:40 +0200
changeset 15665 7e7412fffc0c
parent 14981 e73f8140af78
permissions -rw-r--r--
tuned updates, added map_entry;
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
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     4
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     5
Generic objects of arbitrary type -- fool the ML type system via
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     6
exception constructors.
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
     7
*)
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
signature OBJECT =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    10
sig
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    11
  type T
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    12
  type kind
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    13
  val kind: string -> kind
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    14
  val name_of_kind: kind -> string
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    15
  val eq_kind: kind * kind -> bool
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    16
  val kind_error: kind -> 'a
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    17
end;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    18
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    19
structure Object: OBJECT =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    20
struct
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    21
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
(* anytype values *)
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    24
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    25
type T = exn;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    26
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
(* kinds *)
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    29
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    30
datatype kind = Kind of string * stamp;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    31
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    32
fun kind name = Kind (name, stamp ());
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    33
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    34
fun name_of_kind (Kind (name, _)) = name;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    35
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    36
fun eq_kind (Kind (_, s1), Kind (_, s2)) = s1 = s2;
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    37
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    38
fun kind_error k =
67c5966611c6 moved object.ML to General/object.ML;
wenzelm
parents:
diff changeset
    39
  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
    40
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
end;