Type definitions for constrained polymorphic variants

I have a number of functions with signatures of the form

val f : ([< `A | `B of 'a] as 'a)  -> string

As this is repeated a number of times I’d like to create a type definition for the polymorphic variant. However, when I create the type with the constraint present ([<…]) I get an error. Is there a way to do this?

Yep:

type 'a foo = [< `A | `B of 'a] as 'a

val f : 'a foo -> string

Thanks, this worked perfectly.