blob: e7632cac296b012932c96a99062b0eeffc5ee413 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
type foo = ..
;;
(* Check that abbreviations work *)
type bar = foo = ..
;;
type baz = foo = ..
;;
type bar += Bar1 of int
;;
type baz += Bar2 of int
;;
module M = struct type bar += Foo of float end
;;
module type S = sig type baz += Foo of float end
;;
module M_S = (M : S)
;;
(* Abbreviations need to be made open *)
type foo = ..
;;
type bar = foo
;;
type bar += Bar of int (* Error: type is not open *)
;;
type baz = bar = .. (* Error: type kinds don't match *)
;;
(* Abbreviations need to match parameters *)
type 'a foo = ..
;;
type ('a, 'b) bar = 'a foo = .. (* Error: arrities do not match *)
;;
type ('a, 'b) foo = ..
;;
type ('a, 'b) bar = ('a, 'a) foo = .. (* Error: constraints do not match *)
;;
(* Private abstract types cannot be open *)
type foo = ..
;;
type bar = private foo = .. (* ERROR: Private abstract types cannot be open *)
;;
(* Check that signatures can hide open-ness *)
module M = struct type foo = .. end
;;
module type S = sig type foo end
;;
module M_S = (M : S)
;;
type M_S.foo += Foo (* ERROR: Cannot extend a type that isn't "open" *)
;;
(* Check that signatures cannot add open-ness *)
module M = struct type foo end
;;
module type S = sig type foo = .. end
;;
module M_S = (M : S) (* ERROR: Signatures are not compatible *)
;;
(* Check that signatures maintain variances *)
module M = struct type +'a foo = .. type 'a bar = 'a foo = .. end
;;
module type S = sig type 'a foo = .. type 'a bar = 'a foo = .. end
;;
module M_S = (M : S) (* ERROR: Signatures are not compatible *)
;;
(* Exn is an open type *)
type exn2 = exn = ..
;;
(* Exhaustiveness *)
type foo = ..
type foo += Foo
let f = function Foo -> ()
;; (* warn *)
|