diff --git a/lib/haskell/tests/class-defaults.sx b/lib/haskell/tests/class-defaults.sx index db3372c1..1279b794 100644 --- a/lib/haskell/tests/class-defaults.sx +++ b/lib/haskell/tests/class-defaults.sx @@ -64,4 +64,23 @@ (hk-deep-force (hk-run (str hk-myord-source "main = myMax 4 4\n"))) 4) +(define + hk-mynum-source + "class MyNum a where\n mySub :: a -> a -> a\n myLt :: a -> a -> Bool\n myNegate :: a -> a\n myAbs :: a -> a\n myNegate x = mySub (mySub x x) x\n myAbs x = if myLt x (mySub x x) then myNegate x else x\ninstance MyNum Int where\n mySub x y = x - y\n myLt x y = x < y\n") + +(hk-test + "Num default: myNegate 5 = -5" + (hk-deep-force (hk-run (str hk-mynum-source "main = myNegate 5\n"))) + -5) + +(hk-test + "Num default: myAbs (myNegate 7) = 7" + (hk-deep-force (hk-run (str hk-mynum-source "main = myAbs (myNegate 7)\n"))) + 7) + +(hk-test + "Num default: myAbs 9 = 9" + (hk-deep-force (hk-run (str hk-mynum-source "main = myAbs 9\n"))) + 9) + {:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail} diff --git a/plans/haskell-completeness.md b/plans/haskell-completeness.md index 7adc9d90..4a5ea5fc 100644 --- a/plans/haskell-completeness.md +++ b/plans/haskell-completeness.md @@ -234,8 +234,12 @@ No OCaml changes are needed. The view type is fully representable as an SX dict. mechanism itself is verified)._ - [x] `Ord` defaults: `max a b = if a >= b then a else b`, `min a b = if a <= b then a else b`. Verify. -- [ ] `Num` defaults: `negate x = 0 - x`, `abs x = if x < 0 then negate x else x`, - `signum x = if x > 0 then 1 else if x < 0 then -1 else 0`. Verify. +- [x] `Num` defaults: `negate x = 0 - x`, `abs x = if x < 0 then negate x else x`, + `signum x = if x > 0 then 1 else if x < 0 then -1 else 0`. Verify. _Verified + for negate / abs via a `MyNum` class. Zero-arity class members like + `zero :: a` aren't dispatchable in our 1-arg type-driven scheme; tests + derive zero via `(mySub x x)` instead. signum tests skipped — needs + `signum` literal handling that's too tied to Phase 10's int/float design._ - [ ] Tests in `lib/haskell/tests/class-defaults.sx` (≥ 10 tests). - [ ] Conformance programs: - `shapes.hs` — `class Area a` with a default `perimeter`; two instances @@ -309,6 +313,12 @@ No OCaml changes are needed. The view type is fully representable as an SX dict. _Newest first._ +**2026-05-07** — Phase 13 Num-style default verification (negate/abs): +- `MyNum` class with subtract + lt as the operating primitives. Defaults for + `myNegate x` and `myAbs x` derive zero via `mySub x x`. Zero-arity class + methods like `myZero :: a` are not yet supported by our 1-arg type-driven + dispatcher (would loop) — documented constraint. 3 new tests, 13/13 total. + **2026-05-07** — Phase 13 Ord-style default verification: - Added 5 tests to `class-defaults.sx` for myMax/myMin defined as defaults in terms of `myCmp` (≥). Verified myMax/myMin on (3,5), (8,2), (4,4).