-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Comparing changes
Open a pull request
base repository: microsoft/TypeScript
base: main
head repository: rkirov/TypeScript
compare: master
- 9 commits
- 17 files changed
- 2 contributors
Commits on Mar 15, 2026
-
Add higher-kinded types (HKTs) — v0 proof of concept
Introduce first-class support for abstracting over type constructors via kind annotations in type parameter syntax: `<F : * -> *>`. This enables writing generic abstractions like Functor and Monad that work across Array, Promise, user-defined types, and any type constructor of the right kind — eliminating the need for defunctionalization hacks. What works: - Kind annotation syntax parsed from `<F : * -> *>` (no new tokens) - `Functor<Array>`, `Monad<Box>` — concrete and user-defined constructors - `F<A>` type application resolves to `Array<A>` when F = Array - Monad<F> extends Functor<F> — HKT params forwarded through inheritance - Generic functions: lift, when, sequence all typecheck - Type inference: `boxMonad.pure(42)` infers `Box<number>` - Invariant assignability for abstract constructor applications - Arity checking: `F<A, B>` errors when `F : * -> *` - Full backward compatibility with existing TypeScript code - 12 test cases passing in the standard test suite Compiler changes: - parser.ts: parseKindAnnotation() for `* -> *` syntax - types.ts: kindArity on TypeParameterDeclaration and TypeParameter; hktConstructorSymbol and hktTypeArguments on Type - checker.ts: TypeConstructorRef and HKTApplicationType representations (both piggyback on TypeFlags.Substitution); HKT-aware type argument resolution, instantiation, assignability, and inference Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 960dc97 - Browse repository at this point
Copy the full SHA 960dc97View commit details -
Add HKT playground — interactive browser demo
Self-contained HTML page that loads the custom TypeScript compiler and provides a live type-checking editor with example buttons for Functor, Monad, Sequence, and error cases. Serve from repo root: python3 -m http.server 8080 Open: http://localhost:8080/hkt-playground.html Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for a643e6e - Browse repository at this point
Copy the full SHA a643e6eView commit details -
Upgrade HKT playground to Monaco editor
Replace textarea with Monaco editor for full IDE experience: syntax highlighting, bracket matching, error squigglies, line numbers, and click-to-navigate on diagnostic locations. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 35960b6 - Browse repository at this point
Copy the full SHA 35960b6View commit details -
Add custom hover provider using HKT-aware compiler
Replace Monaco's built-in TypeScript hover (which shows `any` for HKT types) with a custom hover provider that queries our compiler's type checker. Hovering over `fa: F<A>` now shows the correct type from our HKT-aware checker, and type parameters with kind annotations display their kind (e.g., `F : * -> *`). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 1160d44 - Browse repository at this point
Copy the full SHA 1160d44View commit details -
Change kind syntax to uncurried form with tuple parameters
Replace Haskell-style curried kind arrows with explicit tuple syntax: - `* -> *` for one-arg constructors (unchanged) - `(*, *) -> *` for two-arg constructors (was `* -> * -> *`) - `(*) -> *` is sugar for `* -> *` - `(* -> *) -> *` parses but errors: "Higher-order kinds are not yet supported" The parser now handles a full kind grammar with parens, commas, and right-associative arrows. Internally, a KindNode tree is stored on the AST alongside the simple kindArity count. The checker validates that all kind parameters and return are `*`, rejecting higher-order kinds with a clear diagnostic (TS2900). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7b1cbbf - Browse repository at this point
Copy the full SHA 7b1cbbfView commit details -
Support higher-order kinds: (* -> *) -> * and beyond
Remove the "not yet supported" restriction on higher-order kinds. Type constructors can now take other type constructors as parameters: type ApplyToArray<F : (* -> *) -> *> = F<Array> interface Wrapper<F : * -> *> { wrap<A>(a: A): F<A> } Changes: - Store full KindNode tree on TypeParameter (alongside kindArity) - Add kind utilities: kindsMatch(), getKindOfType(), getKindOfSymbol(), kindToString() for recursive kind comparison - resolveTypeConstructorArgument now uses full kind matching instead of simple arity equality - isHKTTypeArgumentContext handles TypeParameter parents (F<Array> where F is itself a higher-kinded parameter) - Force-resolve type alias symbols in isHKTTypeArgumentContext to ensure typeParameters are populated Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>Configuration menu - View commit details
-
Copy full SHA for e374e0d - Browse repository at this point
Copy the full SHA e374e0dView commit details -
Update HKT.md with higher-order kinds and new syntax
Reflect current state: uncurried kind syntax, higher-order kinds supported, 18 tests passing, live demo link. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for dfc8c82 - Browse repository at this point
Copy the full SHA dfc8c82View commit details -
Add Bifunctor and Higher-Order examples to playground
New example tabs showing (*, *) -> * with Pair/Bifunctor and (* -> *) -> * with ApplyToNumber, NaturalTransformation, and nested kind aliases. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 53f29b3 - Browse repository at this point
Copy the full SHA 53f29b3View commit details -
Improve Higher-Order example with Nat composition
Show natural transformations (Nat<F, G> where F, G : * -> *) and composition of natural transformations (composeNat with three * -> * params), demonstrating genuine higher-kinded programming. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b4782dd - Browse repository at this point
Copy the full SHA b4782ddView commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff main...master