Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Is there a way to get the name of variant in type

$
0
0

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>)
}

Playground link

This way, when you add new cases in your variant, the compiler will remind you to add it to your array too.


Viewing all articles
Browse latest Browse all 2592

Trending Articles