- : unit = () type foo = .. type foo += A | B of int val is_a : foo -> bool = type foo Line 2, characters 0-20: 2 | type foo += A of int (* Error type is not open *) ^^^^^^^^^^^^^^^^^^^^ Error: Type definition foo is not extensible type foo = private .. Line 2, characters 12-20: 2 | type foo += A of int (* Error type is private *) ^^^^^^^^ Error: Cannot extend private type definition foo type 'a foo = .. Line 2, characters 0-29: 2 | type ('a, 'b) foo += A of int (* Error: type parameter mismatch *) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: This extension does not match the definition of type foo They have different arities. module type S = sig type foo = private .. type foo += A of float end Line 7, characters 2-24: 7 | type foo += B of float (* Error: foo does not have an extensible type *) ^^^^^^^^^^^^^^^^^^^^^^ Error: Type definition foo is not extensible type foo = .. module M : sig type foo += A of int | B of string type foo += C of int | D of float end module type S = sig type foo += B of string | C of int type foo += D of float type foo += A of int end module M_S : S type 'a foo = .. type _ foo += A : int -> int foo | B : int foo val get_num : 'a foo -> 'a -> 'a option = type 'a foo = .. constraint 'a = [> `Var ] type 'a foo += A of 'a Line 2, characters 10-11: 2 | let a = A 9 (* ERROR: Constraints not met *) ^ Error: This expression has type int but an expression was expected of type [> `Var ] Line 2, characters 19-22: 2 | type 'a foo += B : int foo (* ERROR: Constraints not met *) ^^^ Error: This type int should be an instance of type [> `Var ] type foo = .. module M : sig type foo += A of int end val a1 : foo = M.A 10 module type S = sig type foo += private A of int end module M_S : S val is_s : foo -> bool = Line 2, characters 9-17: 2 | let a2 = M_S.A 20 (* ERROR: Cannot create a value using a private constructor *) ^^^^^^^^ Error: Cannot create values of the private type foo type foo = .. module M : sig type foo += A1 of int end type foo += A2 of int type bar = .. Line 2, characters 17-21: 2 | type bar += A3 = M.A1 (* Error: rebind wrong type *) ^^^^ Error: The constructor M.A1 has type foo but was expected to be of type bar module M : sig type foo += private B1 of int end type foo += private B2 of int Line 2, characters 17-21: 2 | type foo += B3 = M.B1 (* Error: rebind private extension *) ^^^^ Error: The constructor M.B1 is private Line 2, characters 16-23: 2 | type foo += C = Unknown (* Error: unbound extension *) ^^^^^^^ Error: Unbound constructor Unknown module M : sig type foo = private .. type foo += A1 of int end type M.foo += A2 of int type 'a foo = .. type 'a foo1 = 'a foo = .. type 'a foo2 = 'a foo = .. type 'a foo1 += A of int | B of 'a | C : int foo1 type 'a foo2 += D of int | E of 'a | F : int foo2 type +'a foo = .. type 'a foo += A of (int -> 'a) Line 2, characters 0-31: 2 | type 'a foo += B of ('a -> int) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: In this definition, expected parameter variances are not satisfied. The 1st type parameter was expected to be covariant, but it is injective contravariant. Line 2, characters 0-39: 2 | type _ foo += C : ('a -> int) -> 'a foo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: In this definition, expected parameter variances are not satisfied. The 1st type parameter was expected to be covariant, but it is injective contravariant. type 'a bar = .. Line 2, characters 0-32: 2 | type +'a bar += D of (int -> 'a) (* ERROR: type variances do not match *) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: This extension does not match the definition of type bar Their variances do not agree. module M : sig type exn += Foo of int * float | Bar : 'a list -> exn end module M : sig exception Bar : 'a list -> exn exception Foo of int * float end exception Foo of int * float exception Bar : 'a list -> exn module M : sig type exn += Foo of int * float | Bar : 'a list -> exn end type foo = .. type foo += Foo of int * int option | Bar of int option val x : foo * foo = (Foo (3, Some 4), Bar (Some 5)) type foo += Foo of string val y : foo * foo = (, Bar (Some 5)) exception Foo of int * int option exception Bar of int option val x : exn * exn = (Foo (3, Some 4), Bar (Some 5)) type foo += Foo of string val y : exn * exn = (Foo (3, _), Bar (Some 5)) type foo = .. type foo += Foo | Bar of int val extension_name : 'a -> string = val extension_id : 'a -> int = val n1 : string = "Foo" val n2 : string = "Bar" val t : bool = true val f : bool = false val is_foo : 'a -> bool = type foo += Foo val f : bool = false Exception: Invalid_argument "Obj.extension_constructor". Exception: Invalid_argument "Obj.extension_constructor".