type t = IDom of int | ICod | IProd of int | IVec of variance
and variance = Covariant | Contravariant

let flip_variance = function
  | Covariant -> Contravariant
  | Contravariant -> Covariant

let invert_variance = function
  | IDom i -> IDom i
  | ICod -> ICod
  | IProd i -> IProd i
  | IVec v -> IVec (flip_variance v)

let pp_variance fmt = function
  | Covariant -> Format.fprintf fmt "+"
  | Contravariant -> Format.fprintf fmt "-"

let pp fmt = function
  | IDom i -> Format.fprintf fmt "dom<%d>" i
  | ICod -> Format.fprintf fmt "cod"
  | IProd i -> Format.fprintf fmt "proj<%d>" i
  | IVec v -> Format.fprintf fmt "vec<%a>" pp_variance v
