From 622c0851ce509734063a4df2f01f1a96fa64595a Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 5 May 2026 23:26:01 +0000 Subject: [PATCH] =?UTF-8?q?haskell:=20let-polymorphism=20tests=20=E2=80=94?= =?UTF-8?q?=20id/const/nested/twice=20at=20multiple=20types=20(+6=20tests,?= =?UTF-8?q?=20476/476)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- lib/haskell/tests/infer.sx | 12 ++++++++++++ plans/haskell-on-sx.md | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/haskell/tests/infer.sx b/lib/haskell/tests/infer.sx index f5af24f4..3e38fcf0 100644 --- a/lib/haskell/tests/infer.sx +++ b/lib/haskell/tests/infer.sx @@ -134,4 +134,16 @@ (hk-test "infer-prog double" (nth (nth results3 0) 2) "Int -> Int") (hk-test "infer-prog twice" (nth (nth results3 1) 2) "(t3 -> t3) -> t3 -> t3") +(hk-t "let id x = x in id 1" "Int") + +(hk-t "let id x = x in id True" "Bool") + +(hk-t "let id x = x in (id 1, id True)" "(Int, Bool)") + +(hk-t "let const x y = x in (const 1 True, const True 1)" "(Int, Bool)") + +(hk-t "let f x = x in let g y = f y in (g 1, g True)" "(Int, Bool)") + +(hk-t "let twice f x = f (f x) in twice (\x -> x + 1) 5" "Int") + {:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail} diff --git a/plans/haskell-on-sx.md b/plans/haskell-on-sx.md index d3238167..c1641a97 100644 --- a/plans/haskell-on-sx.md +++ b/plans/haskell-on-sx.md @@ -95,7 +95,7 @@ Key mappings: - [x] Report type errors with meaningful positions - [x] Reject untypeable programs that phase 3 was accepting - [x] Type-sig checking: user writes `f :: Int -> Int`; verify -- [ ] Let-polymorphism +- [x] Let-polymorphism - [ ] Unit tests: inference for 50+ expressions ### Phase 5 — typeclasses (dictionary passing) @@ -114,6 +114,14 @@ Key mappings: _Newest first._ +- **2026-05-05** — Phase 4 let-polymorphism tests. `hk-w-let` already + generalises let-bound types with `hk-generalise` before adding them to the + env, so `id :: ∀a. a→a` is instantiated independently at each use site. + 6 new tests in `tests/infer.sx`: identity at Int and Bool separately, identity + tuple `(id 1, id True) → (Int, Bool)`, `const` at two types, nested let with + `f`/`g` sharing the polymorphic binding, and `twice` applied to an arithmetic + lambda. All use the 2-arg `hk-t` form. 476/476 green. + - **2026-05-05** — Phase 4 type-sig checking. `hk-ast-type` converts parsed type AST nodes (`t-con`/`t-var`/`t-fun`/`t-app`/`t-list`/`t-tuple`) to internal type values. `hk-collect-tvars` gathers free type variable names. `hk-check-sig`