2
# * * * # type 'a t = { t : 'a; }
3
# type 'a fold = { fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b; }
4
# val f : 'a list -> 'a fold = <fun>
11
method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
13
# class virtual ['a] vlist :
15
method virtual add : 'a -> 'b
16
method virtual fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
22
method add : int -> 'a
23
method fold : f:('b -> int -> 'b) -> init:'b -> 'b
25
# val ilist2 : 'a list -> 'a vlist = <fun>
31
method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
38
method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
45
method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
46
method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd
53
method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c
54
method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd
56
# class virtual ['a] olist :
57
object method virtual fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end
59
object method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end
66
method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b
68
# class ['a] ostream :
75
method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b
77
# class ['a] ostream1 :
83
method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c
87
# class vari : object method m : [< `A | `B | `C ] -> int end
88
# class vari : object method m : [< `A | `B | `C ] -> int end
89
# module V : sig type v = [ `A | `B | `C ] val m : [< v ] -> int end
90
# class varj : object method m : [< V.v ] -> int end
92
sig class vari : object method m : [< `A | `B | `C ] -> int end end
94
sig class vari : object method m : [< `A | `B | `C ] -> int end end
96
# val v : M.vari = <obj>
100
y:int -> object val x : int val y : int method x : int method y : int end
101
# class color_point :
109
method color : string
116
object val p : point val r : int method distance : #point -> float end
117
# val p0 : point = <obj>
118
val p1 : point = <obj>
119
val cp : color_point = <obj>
120
val c : circle = <obj>
121
val d : float = 11.4536240470737098
122
# val f : < m : 'a. 'a -> 'a > -> < m : 'a. 'a -> 'a > = <fun>
124
let f (x : < m : 'a. 'a -> 'a list >) = (x : < m : 'b. 'b -> 'c >)
126
Error: This expression has type < m : 'a. 'a -> 'a list >
127
but an expression was expected of type < m : 'a. 'a -> 'b >
128
The universal variable 'a would escape its scope
129
# class id : object method id : 'a -> 'a end
130
# class type id_spec = object method id : 'a -> 'a end
131
# class id_impl : object method id : 'a -> 'a end
132
# class a : object method m : bool end
133
and b : object method id : 'a -> 'a end
137
Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a
141
Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a
145
Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b
149
None -> r <- Some x; x
151
Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b
152
# class c : object method m : 'a -> 'b -> 'a end
153
# val f1 : id -> int * bool = <fun>
154
# val f2 : id -> int * bool = <fun>
156
let f3 f = f#id 1, f#id true
158
Error: This expression has type bool but an expression was expected of type
160
# val f4 : id -> int * bool = <fun>
161
# class c : object method m : #id -> int * bool end
162
# class id2 : object method id : 'a -> 'a method mono : int -> int end
163
# val app : int * bool = (1, true)
165
type 'a foo = 'a foo list
166
^^^^^^^^^^^^^^^^^^^^^
167
Error: The type abbreviation foo is cyclic
168
# class ['a] bar : 'a -> object end
169
# type 'a foo = 'a foo bar
170
# - : (< m : 'b. 'b * 'a > as 'a) -> 'c * 'a = <fun>
171
# - : (< m : 'b. 'a * 'b list > as 'a) -> 'a * 'c list = <fun>
173
(< m : 'b. 'a * (< n : 'b; .. > as 'b) > as 'a) ->
174
'a * (< n : 'c; .. > as 'c) = <fun>
175
# - : (< p : 'b. < m : 'b; n : 'a; .. > as 'b > as 'a) ->
176
(< m : 'c; n : 'a; .. > as 'c)
178
# - : (< m : 'b. 'b * < p : 'd. 'd * 'c * 'a > as 'c > as 'a) ->
179
('f * < p : 'g. 'g * 'e * 'a > as 'e)
181
# - : < m : 'a. < p : 'a; .. > as 'b > -> 'b = <fun>
182
# type sum = T of < id : 'a. 'a -> 'a >
183
# - : sum -> 'a -> 'a = <fun>
184
# type record = { r : < id : 'a. 'a -> 'a >; }
185
# - : record -> 'a -> 'a = <fun>
186
# - : record -> 'a -> 'a = <fun>
187
# class myself : object ('a) method self : 'b -> 'a end
194
method switch : zero:(unit -> 'b) -> prev:('a -> 'b) -> 'b
196
# val id : 'a -> 'a = <fun>
197
# class c : object method id : 'a -> 'a end
198
# class c' : object method id : 'a -> 'a end
201
val mutable count : int
204
method old : 'b -> 'b
210
method cons : 'a -> 'b
211
method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c
213
# val sum : int #olist -> int = <fun>
214
# val count : 'a #olist -> int = <fun>
215
# val append : 'a #olist -> ('a #olist as 'b) -> 'b = <fun>
217
# class o : object method x : [> `A ] t -> unit end
218
# class c : object method m : d end
219
and d : ?x:int -> unit -> object end
220
# class d : ?x:int -> unit -> object end
221
and c : object method m : d end
222
# class type numeral = object method fold : ('a -> 'a) -> 'a -> 'a end
223
class zero : object method fold : ('a -> 'a) -> 'a -> 'a end
224
class next : #numeral -> object method fold : ('a -> 'a) -> 'a -> 'a end
225
# class type node_type = object method as_variant : [> `Node of node_type ] end
226
# class node : node_type
227
# class node : object method as_variant : [> `Node of node_type ] end
228
# type bad = { bad : 'a. 'a option ref; }
230
let bad = {bad = ref None};;
232
Error: This field value has type 'a option ref which is less general than
234
# type bad2 = { mutable bad2 : 'a. 'a option ref option; }
235
# val bad2 : bad2 = {bad2 = None}
237
bad2.bad2 <- Some (ref None);;
239
Error: This field value has type 'a option ref option
240
which is less general than 'b. 'b option ref option
241
# val f : < m : 'a. < p : 'a * 'b > as 'b > -> 'c -> unit = <fun>
242
# val f : < m : 'a. 'a * (< p : int * 'b > as 'b) > -> 'b -> unit = <fun>
243
# type 'a t = [ `A of 'a ]
244
# class c : object method m : ([> 'a t ] as 'a) -> unit end
245
# class c : object method m : ([> 'a t ] as 'a) -> unit end
246
# class c : object method m : ([> 'a t ] as 'a) -> 'a end
247
# class c : object method m : ([> `A ] as 'a) option -> 'a end
248
# Characters 145-166:
249
object method virtual visit : 'a.('a visitor -> 'a) end;;
250
^^^^^^^^^^^^^^^^^^^^^
251
Error: This type scheme cannot quantify 'a :
252
it escapes this scope.
253
# type ('a, 'b) list_visitor = < caseCons : 'b -> 'b list -> 'a; caseNil : 'a >
254
type 'a alist = < visit : 'b. ('b, 'a) list_visitor -> 'b >
255
class type ct = object ('a) method fold : ('b -> 'a -> 'b) -> 'b -> 'b end
256
type t = { f : 'a 'b. ('b -> (#ct as 'a) -> 'b) -> 'b; }
258
type t = u and u = t;;
260
Error: The type abbreviation t is cyclic
261
# class ['a] a : object constraint 'a = [> `A of 'a a ] end
262
type t = [ `A of t a ]
264
type ('a,'b) t constraint 'a = 'b and ('a,'b) u = ('a,'b) t;;
266
Error: Constraints are not satisfied in this type.
267
Type ('a, 'b) t should be an instance of ('c, 'c) t
270
# type 'a t constraint 'a = int
272
type 'a u = 'a and 'a v = 'a u t;;
274
Error: Constraints are not satisfied in this type.
275
Type 'a u t should be an instance of int t
276
# type 'a u = 'a constraint 'a = int
277
and 'a v = 'a u t constraint 'a = int
279
# type 'a t = unit constraint 'a = g
281
type 'a u = 'a and 'a v = 'a u t;;
283
Error: Constraints are not satisfied in this type.
284
Type 'a u t should be an instance of g t
285
# type 'a u = 'a constraint 'a = g
286
and 'a v = 'a u t constraint 'a = int
288
type 'a u = < m : 'a v > and 'a v = 'a list u;;
290
Error: In the definition of v, type 'a list u should be 'a u
292
type 'a u = A of 'a t
293
# type 'a t = < a : 'a >
294
# - : ('a t as 'a) -> 'a t = <fun>
295
# type u = 'a t as 'a
297
# - : [> `A ] * t -> int = <fun>
298
# - : [> `A ] * t -> int = <fun>
299
# - : [> `A ] option * t -> int = <fun>
300
# - : [> `A ] option * t -> int = <fun>
301
# - : t * [< `A | `B ] -> int = <fun>
302
# - : [< `A | `B ] * t -> int = <fun>
304
function (`A|`B), _ -> 0 | _,(`A|`B) -> 1;;
305
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
306
Warning 8: this pattern-matching is not exhaustive.
307
Here is an example of a value that is not matched:
308
(`AnyExtraTag, `AnyExtraTag)
309
- : [> `A | `B ] * [> `A | `B ] -> int = <fun>
311
function `B,1 -> 1 | _,1 -> 2;;
312
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313
Warning 8: this pattern-matching is not exhaustive.
314
Here is an example of a value that is not matched:
317
function `B,1 -> 1 | _,1 -> 2;;
319
Warning 11: this match case is unused.
320
- : [< `B ] * int -> int = <fun>
322
function 1,`B -> 1 | 1,_ -> 2;;
323
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
324
Warning 8: this pattern-matching is not exhaustive.
325
Here is an example of a value that is not matched:
328
function 1,`B -> 1 | 1,_ -> 2;;
330
Warning 11: this match case is unused.
331
- : int * [< `B ] -> int = <fun>
333
type ('a, 'b) a = 'a -> unit constraint 'a = [> `B of ('a, 'b) b as 'b]
334
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335
Error: Constraints are not satisfied in this type.
337
([> `B of 'a ], 'a) b as 'a
338
should be an instance of
339
(('b, [> `A of 'b ] as 'c) a as 'b, 'c) b
340
# * class type ['a, 'b] a =
342
constraint 'a = < as_a : ('a, 'b) a as 'c; b : 'b; .. >
343
constraint 'b = < a : 'a; as_b : ('a, 'b) b; .. >
349
constraint 'a = < as_a : ('a, 'b) a; b : 'b; .. >
350
constraint 'b = < a : 'a; as_b : ('a, 'b) b; .. >
352
method as_b : ('a, 'b) b
356
constraint 'a = < a : 'b; as_b : ('b, 'a) b; .. >
357
method as_a : ('b, 'a) a
362
constraint 'a = < as_a : ('a, 'b) a; b : 'b; .. >
364
method as_b : ('a, 'b) b
366
type bt = 'a ca cb as 'a
367
# class c : object method m : int end
368
# val f : unit -> c = <fun>
369
# val f : unit -> c = <fun>
371
let f () = object method private n = 1 method m = {<>}#n end;;
372
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
373
Warning 15: the following private methods were made public implicitly:
375
val f : unit -> < m : int; n : int > = <fun>
377
let f () = object (self:c) method n = 1 method m = 2 end;;
378
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
379
Error: This object is expected to have type c but actually has type
381
The first object type has no method n
383
let f () = object (_:'s) constraint 's = < n : int > method m = 1 end;;
384
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
385
Error: This object is expected to have type < n : int > but actually has type
387
The second object type has no method n
389
object (self: 's) method x = 3 method private m = self end
390
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
391
Error: This object is expected to have type < x : int; .. >
392
but actually has type < x : int >
393
Self type cannot be unified with a closed object type
394
# val o : < x : int > = <obj>
396
(x : <m : 'a. 'a * (<m:'b. 'a * <m:'c. 'c * 'bar> > as 'bar) >);;
398
Error: This expression has type < m : 'b. 'b * < m : 'b * 'a > > as 'a
399
but an expression was expected of type
400
< m : 'b. 'b * (< m : 'b * < m : 'd. 'd * 'c > > as 'c) >
401
Types for method m are incompatible
402
# Characters 176-177:
403
let f (x : foo') = (x : bar');;
405
Error: This expression has type foo' = < m : 'a. 'a * 'a foo >
406
but an expression was expected of type bar' = < m : 'a. 'a * 'a bar >
407
Type 'a foo = < m : 'a * 'a foo > is not compatible with type
408
'a bar = < m : 'a * < m : 'b. 'b * 'a bar > >
409
Type 'a foo = < m : 'a * 'a foo > is not compatible with type
410
< m : 'b. 'b * 'a bar >
411
Types for method m are incompatible
413
(x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('c * 'bar)>)> as 'bar);;
415
Error: This expression has type
416
< m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) >
417
but an expression was expected of type
418
< m : 'a. 'a * ('a * < m : 'c. 'c * ('c * 'd) >) > as 'd
419
Types for method m are incompatible
421
(x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('b * 'bar)>)> as 'bar);;
423
Error: This expression has type
424
< m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) >
425
but an expression was expected of type
426
< m : 'a. 'a * ('a * < m : 'c. 'c * ('a * 'd) >) > as 'd
427
Types for method m are incompatible
429
(x : <m : 'b. 'b * ('b * <m:'c. 'c * 'bar> as 'bar)>);;
431
Error: This expression has type < m : 'b. 'b * ('b * 'a) > as 'a
432
but an expression was expected of type
433
< m : 'b. 'b * ('b * < m : 'd. 'd * 'c > as 'c) >
434
Types for method m are incompatible
436
....(x : <m : 'a. 'a -> ('a * <m:'c. 'c -> 'bar> as 'bar)>
437
:> <m : 'a. 'a -> ('a * 'foo)> as 'foo)..
438
Error: Type < m : 'a. 'a -> ('a * (< m : 'd. 'd -> 'b as 'e > as 'c) as 'b) >
439
is not a subtype of < m : 'a. 'a -> ('a * 'f as 'h) as 'g > as 'f
441
= struct let f (x : <m : 'a. 'a * ('a * 'foo)> as 'foo) = () end;;
442
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
443
Error: Signature mismatch:
444
Modules do not match:
445
sig val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit end
448
val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit
451
val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit
453
val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit
455
= struct type t = <m : 'a. 'a * ('a * 'foo)> as 'foo end;;
456
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
457
Error: Signature mismatch:
458
Modules do not match:
459
sig type t = < m : 'b. 'b * ('b * 'a) > as 'a end
461
sig type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > end
462
Type declarations do not match:
463
type t = < m : 'b. 'b * ('b * 'a) > as 'a
465
type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) >
466
# module M : sig type 'a t type u = < m : 'a. 'a t > end
467
# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end
468
# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end
470
(< m : 'b. 'b -> (< m : 'b. 'b -> 'c * < > > as 'c) * < .. >; .. > as 'a) ->
472
# type t = [ `A | `B ]
473
# type v = private [> t ]
475
# type u = private [< t ]
478
fun x -> (x : v :> u);;
480
Error: Type v = [> `A | `B ] is not a subtype of u = [< `A | `B ]
481
# type v = private [< t ]
483
fun x -> (x : u :> v);;
485
Error: Type u = [< `A | `B ] is not a subtype of v = [< `A | `B ]
487
# type q = private < x : p; .. >
490
fun x -> (x : p :> q);;
492
Error: Type p = < x : p > is not a subtype of q = < x : p; .. >
494
..(x : <m:'a. (<p:int;..> as 'a) -> int>
495
:> <m:'b. (<p:int;q:int;..> as 'b) -> int>)..
496
Error: Type < m : 'a. (< p : int; .. > as 'a) -> int > is not a subtype of
497
< m : 'b. (< p : int; q : int; .. > as 'b) -> int >
499
< m : 'a. (< p : < a : int >; .. > as 'a) -> int > ->
500
< m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int > = <fun>
502
..(x : <m:'a. (<p:<a:int;b:int>;..> as 'a) -> int>
503
:> <m:'b. (<p:<a:int>;..> as 'b) -> int>)..
504
Error: Type < m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int >
505
is not a subtype of < m : 'a. (< p : < a : int >; .. > as 'a) -> int >
507
let f4 x = (x : <p:<a:int;b:int>;..> :> <p:<a:int>;..>);;
508
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
509
Error: Type < p : < a : int; b : int >; .. > is not a subtype of
510
< p : < a : int >; .. >
511
The second object type has no method b
513
< m : 'a. [< `A of < p : int > ] as 'a > ->
514
< m : 'a. [< `A of < > ] as 'a > = <fun>
516
(x : <m:'a. [< `A of < > ] as 'a> :> <m:'a. [< `A of <p:int> ] as 'a>);;
517
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
518
Error: Type < m : 'a. [< `A of < > ] as 'a > is not a subtype of
519
< m : 'a. [< `A of < p : int > ] as 'a >
520
# class c : object method id : 'a -> 'a end
522
# val just : 'a option -> 'a = <fun>
523
# val f : c -> 'a -> 'a = <fun>
524
# val g : c -> 'a -> 'a = <fun>
525
# val h : < id : 'a; .. > -> 'a = <fun>
526
# val f : 'a -> int = <fun>
527
val g : 'a -> int = <fun>
528
# type 'a t = Leaf of 'a | Node of ('a * 'a) t
529
# val depth : 'a t -> int = <fun>
531
function Leaf _ -> 1 | Node x -> 1 + d x
532
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
533
Error: This definition has type 'a t -> int which is less general than
536
function Leaf x -> x | Node x -> 1 + depth x;; (* fails *)
537
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
538
Error: This definition has type int t -> int which is less general than
541
function Leaf x -> x | Node x -> depth x;; (* fails *)
542
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
543
Error: This definition has type 'a t -> 'a which is less general than
546
function Leaf x -> x | Node x -> depth x;; (* fails *)
547
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
548
Error: This definition has type 'a. 'a t -> 'a which is less general than
550
# val r : 'a list * '_b list ref = ([], {contents = []})
551
val q : unit -> 'a list * '_b list ref = <fun>
552
# val f : 'a -> 'a = <fun>
553
# val zero : [> `B of 'a | `Int of int ] as 'a = `Int 0
555
let zero : 'a. [< `Int of int] as 'a = `Int 0;; (* fails *)
557
Error: This expression has type [> `Int of int ]
558
but an expression was expected of type [< `Int of int ]
559
Types for tag `Int are incompatible
560
# type t = { f : 'a. [> `B of 'a | `Int of int ] as 'a; }
561
val zero : t = {f = `Int 0}
563
let zero = {f = `Int 0} ;; (* fails *)
565
Error: This expression has type [> `Int of int ]
566
but an expression was expected of type [< `Int of int ]
567
Types for tag `Int are incompatible
568
# val id : 'a -> 'a = <fun>
569
val neg : int -> bool -> int * bool = <fun>
570
# type t = A of int | B of (int * t) list | C of (string * t) list
571
val transf : (int -> t) -> t -> t = <fun>
572
val transf_alist : (int -> t) -> ('a * t) list -> ('a * t) list = <fun>
573
# type t = { f : 'a. ('a list -> int) Lazy.t; }
574
val l : t = {f = <lazy>}
575
# type t = { f : 'a. 'a -> unit; }
576
# - : t = {f = <fun>}
578
{f=fun ?x y -> y};; (* fail *)
580
Error: This field value has type unit -> unit which is less general than