types.mli 4.64 KB
Newer Older
1 2 3 4
module LabelPool : Pool.T with type value = string
module AtomPool  : Pool.T with type value = string
type label = LabelPool.t
type atom  = AtomPool.t
5
type const = Integer of Big_int.big_int | Atom of atom | Char of Chars.Unichar.t
6

7 8
(** Algebra **)

9 10
type node
type descr
11

12 13
val make: unit -> node
val define: node -> descr -> unit
14

15 16
val cons: descr -> node
val internalize: node -> node
17

18 19
val id: node -> int
val descr: node -> descr
20

21 22 23
val equal_descr: descr -> descr -> bool
val hash_descr: descr -> int

24

25
module DescrHash: Hashtbl.S with type key = descr
26 27 28 29
module DescrMap: Map.S with type key = descr

(* Note: it seems that even for non-functional data, DescrMap
is more efficient than DescrHash ... *)
30

31 32
(** Boolean connectives **)

33 34 35 36 37 38
val cup    : descr -> descr -> descr
val cap    : descr -> descr -> descr
val diff   : descr -> descr -> descr
val neg    : descr -> descr
val empty  : descr
val any    : descr
39

40 41
(** Constructors **)

42
val interval : Intervals.t -> descr
43
val atom     : atom Atoms.t -> descr
44 45 46
val times    : node -> node -> descr
val arrow    : node -> node -> descr
val record   : label -> bool -> node -> descr
47
val char     : Chars.t -> descr
48
val constant : const -> descr
49

50 51 52 53 54 55 56
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
57
  val ty: descr -> v
58 59 60
  val cup: v list -> v
  val times: v -> v -> v

61
  val solve: v -> node
62 63 64 65 66
end

(** Normalization **)

module Product : sig
67
  val any : descr
68 69
  val other : descr -> descr
  val is_product : descr -> bool
70 71 72

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
73
  val is_empty: t -> bool
74
  val get: descr -> t
75 76 77 78 79 80 81 82 83
  val pi1: t -> descr
  val pi2: t -> descr
    
  (* Intersection with (pi1,Any) *)
  val restrict_1: t -> descr -> t

  (* List of non-empty rectangles whose first projection
     are pair-wise disjunct *)
  type normal = t
84 85 86 87
  val normal: descr -> normal

  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
88 89 90
end

module Record : sig
91
  val any : descr
92

93
  (* List of maps label -> (optional, content) *)
94
  type t (* = (label, (bool * descr)) SortedMap.t list *)
95
  val get: descr -> t
96
  val descr: t -> descr
97 98 99 100 101 102 103 104 105 106
  val is_empty: t -> bool
  val restrict_label_present: t -> label -> t
  val restrict_field: t -> label -> descr -> t
  val restrict_label_absent: t -> label -> t
  val project_field: t -> label -> descr

  type normal = 
      [ `Success
      | `Fail
      | `Label of label * (descr * normal) list * normal ]
107
	   
108 109
  val normal: descr -> normal

110 111 112
  val normal': descr -> label -> (descr * descr) list * descr option
  val first_label: descr -> [ `Empty | `Any | `Label of label ]

113
  val project : descr -> label -> descr
114
    (* Raise Not_found if label is not necessarily present *)
115 116
end

117 118
module Arrow : sig
  val any : descr
119

120 121 122 123 124 125 126 127
  val check_strenghten: descr -> descr -> descr
    (* [check_strenghten t s]
       Assume that [t] is an intersection of arrow types
       representing the interface of an abstraction;
       check that this abstraction has type [s] (otherwise raise Not_found)
       and returns a refined type for this abstraction.
    *)

128 129
  val check_iface: (descr * descr) list -> descr -> bool

130
  type t
131
  val is_empty: t -> bool
132 133
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
134

135 136 137
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
138 139 140 141 142 143

  val need_arg : t -> bool
    (* True if the type of the argument is needed to obtain
       the type of the result (must use [apply]; otherwise,
       [apply_noarg] is enough *)
  val apply_noarg : t -> descr
144 145 146
end


147
module Int : sig
148 149
  val has_int : descr -> Big_int.big_int -> bool

150 151 152 153 154 155 156
  val any : descr

  val is_int : descr -> bool
  val get: descr -> Intervals.t
  val put: Intervals.t -> descr
end

157 158 159 160
module Atom : sig
  val has_atom : descr -> atom -> bool
end

161 162
module Char : sig
  val has_char : descr -> Chars.Unichar.t -> bool
163
  val any : descr
164 165
end

166
val normalize : descr -> descr
167

168
(** Subtyping and sample values **)
169

170 171 172
val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool
173

174 175 176
module Sample :
sig
  type t =
177
    | Int of Big_int.big_int
178
    | Atom of atom
179
    | Char of Chars.Unichar.t
180 181 182 183 184 185 186 187 188
    | Pair of t * t
    | Record of (label * t) list
    | Fun of (node * node) list

  val get : descr -> t
	(** 
	  Extract a sample value from a non empty type;
	  raise Not_found for an empty type
	**)
189 190

  val print : Format.formatter -> t -> unit
191 192
end

193 194
module Print :
sig
195
  val register_global : string -> descr -> unit
196
  val print_const : Format.formatter -> const -> unit
197 198
  val print : Format.formatter -> node -> unit
  val print_descr: Format.formatter -> descr -> unit
199
end
200

201
val check: descr -> unit