Extensible Variants
A variant type whose constructors can be added later, possibly in other modules (like exn).
A variant type whose constructors can be added later, possibly in other modules (like exn).
exn is an extensible variant: exception E of int ≡ type exn += E of int.
Use case: plugin systems, extensible error types, Printexc.register_printer.
type message = ..
type message += Greeting of string
type message += Quit | Ping of int
let handle = function
| Greeting s -> "Hello " ^ s
| Ping n -> "Pong " ^ string_of_int n
| Quit -> "bye"
| _ -> "unknown" (* always required: the type is open *)