@@ -36,3 +36,90 @@ type !'a t = (module s with type t = 'a);;
36
36
module type s = sig type t end
37
37
type 'a t = (module s with type t = 'a )
38
38
|}]
39
+
40
+ (* Composition *)
41
+ type -'a n
42
+ type +'a p
43
+ type !'a i
44
+
45
+ type +'a error_np = 'a n p ;;
46
+ [%% expect{|
47
+ type -'a n
48
+ type +'a p
49
+ type !'a i
50
+ Line 5 , characters 0-26 :
51
+ 5 | type +'a error_np = 'a n p ;;
52
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
53
+ Error : In this definition , expected parameter variances are not satisfied .
54
+ The 1 st type parameter was expected to be covariant,
55
+ but it is contravariant .
56
+ |}]
57
+
58
+
59
+ type +'a error_pn = 'a p n ;;
60
+ [%% expect{|
61
+ Line 1 , characters 0-26 :
62
+ 1 | type + 'a error_pn = 'a p n;;
63
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
64
+ Error : In this definition, expected parameter variances are not satisfied.
65
+ The 1 st type parameter was expected to be covariant,
66
+ but it is contravariant.
67
+ | }]
68
+
69
+ type -'a error_pp = 'a p p ;;
70
+ [%% expect{|
71
+ Line 1 , characters 0-26 :
72
+ 1 | type - 'a error_pp = 'a p p;;
73
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
74
+ Error : In this definition, expected parameter variances are not satisfied.
75
+ The 1 st type parameter was expected to be contravariant,
76
+ but it is covariant.
77
+ | }]
78
+
79
+ type -'a error_nn = 'a n n ;;
80
+ [%% expect{|
81
+ Line 1 , characters 0-26 :
82
+ 1 | type - 'a error_nn = 'a n n;;
83
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
84
+ Error : In this definition, expected parameter variances are not satisfied.
85
+ The 1 st type parameter was expected to be contravariant,
86
+ but it is covariant.
87
+ | }]
88
+
89
+ type !'a inj_in = 'a i n
90
+ [%% expect{|
91
+ Line 1 , characters 0-24 :
92
+ 1 | type ! 'a inj_in = 'a i n
93
+ ^^^^^^^^^^^^^^^^^^^^^^^^
94
+ Error : In this definition, expected parameter variances are not satisfied.
95
+ The 1 st type parameter was expected to be injective invariant,
96
+ but it is invariant.
97
+ | }]
98
+
99
+ type !'a inj_in = 'a n i
100
+ [%% expect{|
101
+ Line 1 , characters 0-24 :
102
+ 1 | type ! 'a inj_in = 'a n i
103
+ ^^^^^^^^^^^^^^^^^^^^^^^^
104
+ Error : In this definition, expected parameter variances are not satisfied.
105
+ The 1 st type parameter was expected to be injective invariant,
106
+ but it is invariant.
107
+ | }]
108
+
109
+ module Make_covariant (M : sig type 'a t end ): sig
110
+ type 'a i = 'a
111
+ type +'a t = 'a i M .t
112
+ end = struct
113
+ type 'a i = 'a
114
+ type +'a t = 'a i M .t
115
+ end
116
+
117
+ module Positive_ref = Make_covariant (struct type 'a t = 'a ref end )
118
+ [%% expect {|
119
+ Line 6 , characters 2-23 :
120
+ 6 | type + 'a t = 'a i M. t
121
+ ^^^^^^^^^^^^^^^^^^^^^
122
+ Error : In this definition, expected parameter variances are not satisfied.
123
+ The 1 st type parameter was expected to be covariant,
124
+ but it is invariant.
125
+ | }]
0 commit comments