types.mli 5.43 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
9
10
11
12
13
14
15
16
17
18
19
20

(** Algebra **)

type node
type descr

val make: unit -> node
val define: node -> descr -> unit

val cons: descr -> node
val internalize: node -> node

val id: node -> int
val descr: node -> descr

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
33
34
35
36
37
38
39
40
41
(** Boolean connectives **)

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

(** Constructors **)

42
43
type pair_kind = [ `Normal | `XML ]

44
val interval : Intervals.t -> descr
45
val atom     : atom Atoms.t -> descr
46
val times    : node -> node -> descr
47
val xml      : node -> node -> descr
48
49
val arrow    : node -> node -> descr
val record   : label -> bool -> node -> descr
50
val record'  : bool * (label, (bool * node)) SortedMap.t -> descr
51
val char     : Chars.t -> descr
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
val constant : const -> descr

(** Positive systems and least solutions **)

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

  val solve: v -> node
end

(** Normalization **)

module Product : sig
  val any : descr
72
73
74
  val any_xml : descr
  val other : ?kind:pair_kind -> descr -> descr
  val is_product : ?kind:pair_kind -> descr -> bool
75
76
77

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
78
  val is_empty: t -> bool
79
  val get: ?kind:pair_kind -> descr -> t
80
81
82
83
84
85
86
87
88
  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
89
  val normal: ?kind:pair_kind -> descr -> normal
90
91
92

  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
93
94
95
end

module Record : sig
96
97
98
99
100
101
102
103
  type t
  val get : descr -> t
  val descr: t -> descr
  val is_empty: t -> bool
  val restrict_field : t -> label -> descr -> t
  val restrict_label_absent: t -> label -> t
  val restrict_label_present: t -> label -> t
  val label_present: t -> label -> (descr * t) list
104
105
  val somefield_possible: t -> bool
  val nofield_possible: t -> bool
106
  val any : descr
107
108
  val project_field: t -> label -> descr
  val project : descr -> label -> descr
109

110
(*
111
  (* List of maps label -> (optional, content) *)
112
  type t (* = (label, (bool * descr)) SortedMap.t list *)
113
  val get: descr -> t
114
  val descr: t -> descr
115
116
117
118
119
  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
120
*)
121
122

  type normal = 
123
124
125
126
      [ `Success   (* { } *)
      | `Fail      (* Empty *)
      | `NoField   (* {| |} *)
      | `SomeField (* { } \ {| |} *)
127
      | `Label of label * (descr * normal) list * normal ]
128
	   
129
130
  val normal: descr -> normal

131
132
  val normal': t -> label -> (descr * t) list * t
  val first_label: t -> [ `Success|`Fail|`NoField|`SomeField|`Label of label ]
133

134
(*
135
136
  val project : descr -> label -> descr
    (* Raise Not_found if label is not necessarily present *)
137
*)
138
139
end

140
141
module Arrow : sig
  val any : descr
142

143
144
145
146
147
148
149
150
  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.
    *)

151
152
  val check_iface: (descr * descr) list -> descr -> bool

153
  type t
154
  val is_empty: t -> bool
155
156
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
157

158
159
160
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
161
162
163
164
165
166

  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
167
168
169
end


170
module Int : sig
171
172
  val has_int : descr -> Big_int.big_int -> bool

173
174
175
176
177
178
179
  val any : descr

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

180
181
182
183
module Atom : sig
  val has_atom : descr -> atom -> bool
end

184
185
module Char : sig
  val has_char : descr -> Chars.Unichar.t -> bool
186
  val any : descr
187
188
end

189
val normalize : descr -> descr
190
191
192
193
194
195
196
197
198
199

(** Subtyping and sample values **)

val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool

module Sample :
sig
  type t =
200
    | Int of Big_int.big_int
201
    | Atom of atom
202
    | Char of Chars.Unichar.t
203
204
    | Pair of (t * t)
    | Xml of (t * t)
205
206
    | Record of (label * t) list
    | Fun of (node * node) list
207
    | Other
208
209
210
211
212
213

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

  val print : Format.formatter -> t -> unit
216
217
218
219
end

module Print :
sig
220
  val register_global : string -> descr -> unit
221
  val print_const : Format.formatter -> const -> unit
222
223
224
225
226
  val print : Format.formatter -> node -> unit
  val print_descr: Format.formatter -> descr -> unit
end

val check: descr -> unit