Skip to content

Compute a mapped type family's image at the use site - #61

Merged
thomasjm merged 5 commits into
masterfrom
use-site-family-image
Oct 14, 2026
Merged

thomasjm merged 5 commits into
masterfrom
use-site-family-image

Conversation

@thomasjm

Copy link
Copy Markdown
Contributor

typeFamiliesToMapToTypeScript only handled a single-argument family with a concrete image, so a mode-indexed family whose result is one of its own arguments was rejected outright:

type family IsHydrated (f :: Type -> Type) x y where
IsHydrated Dry x y = x
IsHydrated Wet x y = y

The use site fixes those arguments, and then the image is concrete. Substituting them before tabulating turns such a record into one generic declaration indexed on the mode, rather than one specialized declaration per instantiation sharing a name.

A variable that keys a mapped family is now an eligible generic variable whatever its kind, tables are named per use site so two sites of one family don't collide, and the placeholder each table generates is memoized per module.

Still out of reach: a family whose choice type mentions another of the record's variables, and one whose keys aren't plain constructors (beam's Columnar).

@thomasjm
thomasjm force-pushed the use-site-family-image branch from 71d6680 to b68bad3 Compare October 13, 2026 21:01
typeFamiliesToMapToTypeScript only handled a single-argument family with a concrete image, so
a mode-indexed family whose result is one of its own arguments was rejected outright:

  type family IsHydrated (f :: Type -> Type) x y where
    IsHydrated Dry x y = x
    IsHydrated Wet x y = y

The use site fixes those arguments, and then the image is concrete. Substituting them before
tabulating turns such a record into one generic declaration indexed on the mode, rather than
one specialized declaration per instantiation sharing a name.

A variable that keys a mapped family is now an eligible generic variable whatever its kind,
tables are named per use site so two sites of one family don't collide, and the placeholder
each table generates is memoized per module.

Still out of reach: a family whose choice type mentions another of the record's variables, and
one whose keys aren't plain constructors (beam's Columnar).
@thomasjm
thomasjm force-pushed the use-site-family-image branch from f90cc20 to 4fef560 Compare October 14, 2026 09:46
@thomasjm
thomasjm merged commit cd0a870 into master Oct 14, 2026
22 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant