1functor F X:sig type t end = struct datatype u = C of X.t ref end
2
3structure  A = F (struct type t = unit end);
4val ok = op = : A.u * A.u -> bool;
5
6structure  B = F (struct type t = unit -> unit end);
7val ok = op = : B.u * B.u -> bool;
8
9functor G X:sig type t end = struct datatype u = C of X.t end;
10structure C = G(struct type t = unit end);
11val fail = op = : C.u * C.u -> bool;
12structure D = G(struct type t = unit -> unit end);
13val fail = op = : D.u * D.u -> bool;
14
15functor H X:sig eqtype t end = struct datatype u = C of X.t end;
16structure E = H(struct type t = unit end);
17val ok = op = : E.u * E.u -> bool;
18
19functor I X:sig type s eqtype t end = struct datatype u = C of X.t end;
20structure F = I(struct type s = unit type t = unit end);
21val ok = op = : F.u * F.u -> bool;
22structure G = I(struct type s = unit -> unit type t = unit end);
23val ok = op = :G.u * G.u -> bool;
24
25
26functor ok(F:functor X:sig type t end -> sig eqtype u end) =
27    op F:functor X:sig type t end -> sig eqtype u end;
28
29(* test contra-variant domain *)
30functor ok(F:functor X:sig type t end -> sig eqtype u end) =
31    op F:functor X:sig eqtype t end -> sig eqtype u end;
32
33(* test co-variant range *)
34functor ok(F:functor X:sig type t end -> sig eqtype u end) =
35    op F:functor X:sig type t end -> sig type u end;
36
37(* test contra-variant domain and  co-variant range *)
38
39functor ok(F:functor X:sig type t end -> sig eqtype u end) =
40    op F:functor X:sig eqtype t end -> sig type u end;
41
42(* test co-variant domain fails *)
43
44functor fail(F:functor X:sig eqtype t end -> sig type u end) =
45    op F:functor X:sig type t end -> sig type u end;
46
47(* test contra-variant range fails *)
48functor fail(F:functor X:sig eqtype t end -> sig type u end) =
49    op F:functor X:sig eqtype t end -> sig eqtype u end;
50
51
52(* test equality attribute matching of type abbreviations with free variables *)
53
54fun f x = let structure X as sig type t = 'a end = x in x end;
55val g = f : [sig type t = int -> int end] -> [sig type t = int -> int end];
56val p = [structure struct type t = int -> int end as sig type t = int -> int end];
57val ok = f p;
58val ok = g p;
59
60(* test equality attribute matching of type abbreviations with free equality type variables *)
61fun f x = let structure X as sig type t = ''a end = x in x end;
62val g = f : [sig type t = int * int end] -> [sig type t = int * int end];
63val p = [structure struct type t = int * int end as sig type t = int * int end];
64val q = [structure struct type t = ''b * ''b end as sig type t = ''b * ''b end];
65val r = [structure struct type t = ''b * 'c  end as sig type t = ''b * 'c end];
66val t = [structure struct type t = int -> int end as sig type t = int -> int end];
67val ok = f p;
68val ok = g p;
69val ok = f q;
70val ok = f r;
71val fail = f t;
72
73(* ok to realise equality type constructor by equality type *)
74fun ok x = let structure X as sig eqtype t end where type t = ''a = x in x end;
75fun ok x = let structure X as sig eqtype t end where type t = ''a * ''b = x in x end;
76fun ok x = let structure X as sig eqtype 'b t end where type 'b t = ''a * 'b = x in x end;
77
78(* wrong to realise equality type constructor by nonequality type *)
79fun fail x = let structure X as sig eqtype t end where type t = 'a = x in x end;
80fun fail x = let structure X as sig eqtype t end where type t = ''a -> ''b  = x in x end;
81fun fail x = let structure X as sig eqtype 'b t end where type 'b t = 'a -> 'b = x in x end;
82
83
84
85