I’m interested in obtaining a version of the typed AST, where the constructors
Tstr_value carry the list of type variables that are introduced for these constructs, when the body admits a polymorphic type.
Back in 2009, I implemented a quick patch to the compiler for that. Since then, the compiler has evolved, and I would like to rebase my work on a recent version of the compiler.
I’ve already asked the question a few years ago, but things may have evolved, hence I’m asking the question again: Does the current compiler, or a branch thereof, implements the tracking of type variables? If not, would there be interest in integrating this feature in the typechecker?
Note: At a high level, the implementation consists in opening a fresh scope for every let-binding, registering in the current scope fresh type variables (in
newty2, when the type variable is not associated with any structure), and when closing the scope gathering the duplication-free list of type variables that have been generalized (
t.level = generic_level), and storing that list in the let-constructor of the typedtree (e.g.
Texp_let(rec_flag, fvs, pat_exp_list, body), where
fvs denotes that list). The patch is less than 100 lines.
If you think of complications related to GADTs, or other advanced features, please let me know.