GADTs and recursive types

Continuing the discussion from Long term goals vis-à-vis TypeScript?:

@MarcC I realize my message wording was wrong. Let me correct it here. I said:

ReScript types will be non-recursive (this can’t be changed).

I should have said: ReScript types are non-recursive by default but this can be changed on a per-type basis, e.g.:

type rec expr<_> =
| Unit: expr<unit>
| Int(int): expr<int>

So you see, both recursive types and GADTs work in ReScript.

What you can’t change in ReScript is the default that types must be non-recursive.


I wonder if GADTs will ever become endorsed by the ReScript team. I find them definitely harder to grasp than monadic let or most of the infix operators :slight_smile:

EDIT: Saw the ryyppy’s answer. I guess my doubts are justified.

They aren’t a problem in the same way as infix operators. When an infix operator is used in a popular library it means that everyone’s code using the library become harder to read as a result (Like lens in Haskell). Monadic operators also add overhead and a learning curve for the user consuming the library. Contrast this with GADTs, where libraries that use them produce better DX for the consumer of the library without really making it harder to use. A user can use a library with GADTs without any knowledge whatsoever as GADTs become an implementation detail. Personally, it’s a feature I really miss when using Typescript :slight_smile: .

With that said, if GADTs where used everywhere and you couldn’t really start using the language without knowing them I would respect the decision not to include them in Rescript more.


GADTs are mentioned here:

Variants, in their many forms (polymorphic variant, open variant, GADT, etc.), are likely the feature of a type system such as ReScript’s.

This seems pretty much like an endorsement to me.

1 Like

I really hope GADTs are here to stay, they’re for example a great way to model inheritance in bindings.


Hmm, that sounds interesting, can you point me to this technique?

EDIT: do you mean the ‘union type’ trick? –yeah, this was certainly a neat technique.


One key point here is that you don’t have to fully understand all forms of variants or the theory behind them in order to get benefits. Maybe beginners start using them as enums, union types, they learn about exhaustiveness, sum/product types and other concepts and eventually they’ll come up with clean / expressive models using ADTs by experimenting or reading articles etc. I mean it’s not like “If you want to use them read these academic papers or book X”, use them as much as you like or what is enough for you/your team and enjoy the benefits.

Anyway I think this feature is a selling point for rescript. It’s common in js/ts community to mimic ADT behaviour using external libraries, noisy tags or string abuse.


yes this and some other techniques I incorrectly labeled as GADTs in my head (like using phantom types as you did for your version of bs-webapi) ^^

1 Like

Unfortunately not always. GADT require careful knowledge of sometime annotating call sites.
They’re an ok feature. A bit abused in the past community, which we hope won’t happen again.

Hi, I don’t think you should be too worried about we’re going to remove language features.
We only remove things when the benefit justifies it, you can say that we may discourage its wild use but we are not going to make a dumb language