Couldn't records be solved entirely at the type level?

You should, uh, have a look at PureScript—not as a solution to all your problems (there are several divergences in design from Haskell, most notably based-on-JS-ecosystem and strict-by-default, that prevent it from being a drop-in replacement for most people), but as a working ‘prototype’ (over a decade old at this point) of row types used to do exactly this, with dot syntax on records, primitive classes for type-level row operations, etc.

(And, because the grass is always greener elsewhere, having solved compiler-supported row-type-based product types, I find it nigh-intolerable that PureScript doesn’t yet have good syntax for working with variants, a.k.a. compiler-supported row-type-based sum types. The language maintainer’s work is never done.)

3 Likes