types.mli 4.68 KB
Newer Older
1
2
type label = int
type atom  = int
3
type const = Integer of Big_int.big_int | Atom of atom | Char of Chars.Unichar.t
4

5
6
(** Algebra **)

7
8
type node
type descr
9

10
11
val make: unit -> node
val define: node -> descr -> unit
12

13
14
val cons: descr -> node
val internalize: node -> node
15

16
17
val id: node -> int
val descr: node -> descr
18

19
20
21
val equal_descr: descr -> descr -> bool
val hash_descr: descr -> int

22

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

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

29
30
(** Boolean connectives **)

31
32
33
34
35
36
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
37

38
39
(** Constructors **)

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

48
49
50
51
52
53
54
(** Positive systems and least solutions **)

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

59
  val solve: v -> node
60
61
end

62
63
64
65
66
67
68
69
(** Labels and atom names **)

val mk_atom  : string -> atom
val atom_name : atom -> string

val label : string -> label
val label_name : label -> string

70
71
72
(** Normalization **)

module Product : sig
73
  val any : descr
74
75
  val other : descr -> descr
  val is_product : descr -> bool
76
77
78

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

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

module Record : sig
97
  val any : descr
98

99
  (* List of maps label -> (optional, content) *)
100
  type t (* = (label, (bool * descr)) SortedMap.t list *)
101
  val get: descr -> t
102
  val descr: t -> descr
103
104
105
106
107
108
109
110
111
112
  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 ]
113
	   
114
115
  val normal: descr -> normal

116
117
118
  val normal': descr -> label -> (descr * descr) list * descr option
  val first_label: descr -> [ `Empty | `Any | `Label of label ]

119
  val project : descr -> label -> descr
120
    (* Raise Not_found if label is not necessarily present *)
121
122
end

123
124
module Arrow : sig
  val any : descr
125

126
127
128
129
130
131
132
133
  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.
    *)

134
135
  val check_iface: (descr * descr) list -> descr -> bool

136
  type t
137
  val is_empty: t -> bool
138
139
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
140

141
142
143
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
144
145
146
147
148
149

  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
150
151
152
end


153
module Int : sig
154
155
  val has_int : descr -> Big_int.big_int -> bool

156
157
158
159
160
161
162
  val any : descr

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

163
164
165
166
module Atom : sig
  val has_atom : descr -> atom -> bool
end

167
168
module Char : sig
  val has_char : descr -> Chars.Unichar.t -> bool
169
  val any : descr
170
171
end

172
val normalize : descr -> descr
173

174
(** Subtyping and sample values **)
175

176
177
178
val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool
179

180
181
182
module Sample :
sig
  type t =
183
    | Int of Big_int.big_int
184
    | Atom of atom
185
    | Char of Chars.Unichar.t
186
187
188
189
190
191
192
193
194
    | 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
	**)
195
196

  val print : Format.formatter -> t -> unit
197
198
end

199
200
module Print :
sig
201
  val register_global : string -> descr -> unit
202
  val print_const : Format.formatter -> const -> unit
203
204
  val print : Format.formatter -> node -> unit
  val print_descr: Format.formatter -> descr -> unit
205
end
206

207
val check: descr -> unit