Files
rose-ash/lib/haskell/tests/class-defaults.sx
giles 8dfb3f6387
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
haskell: Phase 13 — Eq default verification (+5 tests, class-defaults.sx 5/5)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 13:08:12 +00:00

39 lines
1.4 KiB
Plaintext

;; class-defaults.sx — Phase 13: class default method implementations.
;; ── Eq default: myNeq derived from myEq via `not (myEq x y)` ──
(define
hk-myeq-source
"class MyEq a where\n myEq :: a -> a -> Bool\n myNeq :: a -> a -> Bool\n myNeq x y = not (myEq x y)\ninstance MyEq Int where\n myEq x y = x == y\n")
(hk-test
"Eq default: myNeq 3 5 = True (no explicit myNeq in instance)"
(hk-deep-force (hk-run (str hk-myeq-source "main = myNeq 3 5\n")))
(list "True"))
(hk-test
"Eq default: myNeq 3 3 = False"
(hk-deep-force (hk-run (str hk-myeq-source "main = myNeq 3 3\n")))
(list "False"))
(hk-test
"Eq default: myEq still works in same instance"
(hk-deep-force (hk-run (str hk-myeq-source "main = myEq 7 7\n")))
(list "True"))
;; ── Override path: instance can still provide the method explicitly. ──
(hk-test
"Default override: instance-provided beats class default"
(hk-deep-force
(hk-run
"class Hi a where\n greet :: a -> String\n greet x = \"default\"\ninstance Hi Bool where\n greet x = \"override\"\nmain = greet True"))
"override")
(hk-test
"Default fallback: empty instance picks default"
(hk-deep-force
(hk-run
"class Hi a where\n greet :: a -> String\n greet x = \"default\"\ninstance Hi Bool where\nmain = greet True"))
"default")
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}