|
1 | 1 | module Stack : sig |
| 2 | + (** Stack of unification equations. *) |
| 3 | + |
2 | 4 | type elt = Type.t * Type.t |
| 5 | + (** Unification equations are pairs of types. *) |
| 6 | + |
3 | 7 | type t |
| 8 | + (** The type of stack. *) |
4 | 9 |
|
5 | 10 | val empty : t |
| 11 | + (** An empty stack. *) |
| 12 | + |
6 | 13 | val is_empty : t -> bool |
| 14 | + (** [is_empty s] returns true if [s] is empty. *) |
| 15 | + |
7 | 16 | val pop : t -> (elt * t) option |
| 17 | + (** [pop s] returns [None] if [s] is empty and [Some (eq, tl)] where [eq] is |
| 18 | + the last pushed equation on the stack and [tl] is the rest of the stack. |
| 19 | + *) |
| 20 | + |
8 | 21 | val push : t -> Type.t -> Type.t -> t |
| 22 | + (** [push s t1 t2] returns a stack where the equation [(t1, t2)] is added at the |
| 23 | + top of [s]. |
| 24 | + *) |
| 25 | + |
9 | 26 | val push_array2 : t -> Type.t array -> Type.t array -> t |
| 27 | + (** [push_array2 s a1 a2] zip [a1] and [a2] to make equatins and push them on |
| 28 | + top of [s]. |
| 29 | + @raise Invalid_argument if [a1] and [a2] do not have the same length. |
| 30 | + *) |
| 31 | + |
10 | 32 | val of_list : elt list -> t |
| 33 | + (** Convert a list of equation into a stack. *) |
| 34 | + |
11 | 35 | val pp : t Fmt.t [@@warning "-32"] [@@ocaml.toplevel_printer] |
| 36 | + (** Pretty printer *) |
12 | 37 | end |
13 | 38 |
|
14 | 39 | type return = Done | FailUnif of Type.t * Type.t | FailedOccurCheck of Env.t |
| 40 | +(** The type representing the result of the unification procedure. |
| 41 | + [Done] means that the unification succed |
| 42 | + [FailUnif (t1, t2)] means that the unification failed because of the equality [(t1, t2)] |
| 43 | + [FailedOccurCheck] means that the unification failed because there is a non |
| 44 | + solvable cycle in the environnement. |
| 45 | +*) |
15 | 46 |
|
16 | 47 | module Infix : sig |
17 | 48 | val ( let* ) : return -> ( unit -> return ) -> return |
18 | 49 | end |
19 | 50 |
|
20 | | -val ( let* ) : return -> ( unit -> return ) -> return |
| 51 | +include module type of Infix |
21 | 52 |
|
22 | 53 | val occur_check : Env.t -> return |
| 54 | +(** [occur_check env] checks if the substitution defined by [env] contains cycle. |
| 55 | + Because of collapses, if [env] contains cycles, [occur_check] tries to collapse them |
| 56 | + to make [env] cycle free. |
| 57 | +*) |
23 | 58 |
|
24 | 59 | val process_stack : Env.t -> Stack.t -> return |
| 60 | +(** [process_stack env s] given an unification environment [env] and a stack [s] |
| 61 | + of unification equations, processes each equations. |
| 62 | +*) |
25 | 63 |
|
26 | 64 | val insert : Env.t -> Type.t -> Type.t -> return |
| 65 | +(** [insert env t1 t2] process the unification equation [t1 ≡ t2]. *) |
27 | 66 |
|
28 | 67 | val insert_var : Env.t -> Variable.t -> Type.t -> return |
| 68 | +(** [insert_var env v t] process the unification equation [v ≡ t]. *) |
29 | 69 |
|
30 | 70 | val attach : Env.t -> Variable.t -> Type.t -> return |
| 71 | +(** [attach env v t] modify the substitution represented by [env] by associating |
| 72 | + [t] to [v]. |
| 73 | +*) |
31 | 74 |
|
32 | 75 | val debug : ((('a, Format.formatter, unit, string) format4 -> 'a) -> string) -> unit |
0 commit comments