Pvem: Implementation Notes

Implementation Notes

Why Polymorphic Variants

Using

type ('a, 'b) t =
  | Ok of 'a
  | Error of 'b

gives two annoying alternatives:

  • be incompatible with Core_kernel's Result.t, or
  • depend on Core_kernel.

Type equality constraints do not work twice. I.e. one cannot write:

type ('a, 'b) result_core = ('a, 'b) Result.t  = Ok of 'a | Error of 'b
type ('a, 'b) result_err = ('a, 'b) Err.t  = Ok of 'a | Error of 'b
type ('a, 'b) result = ('a, 'b) result_err  = ('a, 'b) result_core

Polymorphic Variants are safe while not enforcing library dependencies.

Alternatives

The following libraries use “regular/ordinary” variants and hence are all incompatible from each other: