haskell: dict-passing elaborator — runtime dispatch via hk-mk-lazy-builtin (+3 tests, 506/506)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 35s

This commit is contained in:
2026-05-06 08:56:39 +00:00
parent 41a69ecca7
commit 60a8eb24e0
2 changed files with 97 additions and 7 deletions

View File

@@ -32,4 +32,29 @@
(has-key? (get env-full "dictMyEq_Int") "myEq")
true)
(hk-test
"dispatch: single-arg method works"
(hk-deep-force
(hk-run
"class Describable a where\n describe :: a -> String\ninstance Describable Int where\n describe x = \"an integer\"\nmain = describe 42"))
"an integer")
(hk-test
"dispatch: second instance (Bool)"
(hk-deep-force
(hk-run
"class Describable a where\n describe :: a -> String\ninstance Describable Bool where\n describe x = \"a boolean\"\ninstance Describable Int where\n describe x = \"an integer\"\nmain = describe True"))
"a boolean")
(hk-test
"dispatch: error on unknown instance"
(guard
(e (true (>= (index-of e "No instance") 0)))
(begin
(hk-deep-force
(hk-run
"class Describable a where\n describe :: a -> String\nmain = describe 42"))
false))
true)
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}