haskell: let-polymorphism tests — id/const/nested/twice at multiple types (+6 tests, 476/476)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 23:26:01 +00:00
parent d8f3f8c3b2
commit 622c0851ce
2 changed files with 21 additions and 1 deletions

View File

@@ -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}

View File

@@ -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`