# type foo = .. # type foo += A | B of int # val is_a : foo -> bool = # type foo # Characters 13-21: type foo += A of int (* Error type is not open *) ^^^^^^^^ Error: Cannot extend type definition foo # type 'a foo = .. # Characters 1-30: 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 type foo += A of float end # Characters 84-106: type foo += B of float (* Error foo does not have an extensible type *) ^^^^^^^^^^^^^^^^^^^^^^ Error: Type 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 # Characters 11-12: let a = A 9 (* ERROR: Constraints not met *) ^ Error: This expression has type int but an expression was expected of type [> `Var ] # Characters 20-23: 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 = # Characters 10-18: 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 = .. # Characters 18-22: 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 # Characters 18-22: type foo += B3 = M.B1 (* Error: rebind private extension *) ^^^^ Error: The constructor M.B1 is private # Characters 13-24: type foo += C = Unknown (* Error: unbound extension *) ^^^^^^^^^^^ Error: Unbound constructor Unknown # module M : sig type foo 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) # Characters 1-32: type 'a foo += B of ('a -> int) (* ERROR: Parameter variances are not satisfied *) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: In this definition, expected parameter variances are not satisfied. The 1st type parameter was expected to be covariant, but it is injective contravariant. # Characters 1-40: type _ foo += C : ('a -> int) -> 'a foo (* ERROR: Parameter variances are not satisfied *) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 = .. # Characters 1-33: 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 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_name". # Exception: Invalid_argument "Obj.extension_id". #