I don’t think you can generate this automatically, but I’d say it’s not much of a big deal to write it yourself.
There’s a technique that allows you to make sure you didn’t forget a case in your array:
module Foo: {
type t = Bar | Baz
let elements: array<t>
} = {
type t = Bar | Baz
type dup = Bar | Baz // warning : unused constructor Baz.
let elements = ([Bar] :> array<t>)
}
This way, when you add new cases in your variant, the compiler will remind you to add it to your array too.