haskell: Phase 10 — Fractional stub: recip + fromRational (+3 tests, 31/31)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m21s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -809,6 +809,11 @@
|
||||
env
|
||||
"truncate"
|
||||
(hk-mk-builtin "truncate" (fn (x) (truncate x)) 1))
|
||||
(dict-set! env "recip" (hk-mk-builtin "recip" (fn (x) (/ 1 x)) 1))
|
||||
(dict-set!
|
||||
env
|
||||
"fromRational"
|
||||
(hk-mk-builtin "fromRational" (fn (x) x) 1))
|
||||
(let
|
||||
((--sx-to-hk-- (fn (lst) (if (empty? lst) (list "[]") (list ":" (first lst) (--sx-to-hk-- (rest lst))))))
|
||||
(--words--
|
||||
|
||||
@@ -156,4 +156,13 @@
|
||||
(hk-deep-force (hk-run "main = truncate (negate 3.7)"))
|
||||
-3)
|
||||
|
||||
(hk-test "recip 4.0 = 0.25" (hk-deep-force (hk-run "main = recip 4.0")) 0.25)
|
||||
|
||||
(hk-test "1.0 / 4.0 = 0.25" (hk-deep-force (hk-run "main = 1.0 / 4.0")) 0.25)
|
||||
|
||||
(hk-test
|
||||
"fromRational 0.5 = 0.5 (identity)"
|
||||
(hk-deep-force (hk-run "main = fromRational 0.5"))
|
||||
0.5)
|
||||
|
||||
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}
|
||||
|
||||
@@ -162,7 +162,9 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
||||
tests like `show 42 = "42"` rely on this rendering. Documented in `numerics.sx`._
|
||||
- [x] Math builtins: `sqrt`, `floor`, `ceiling`, `round`, `truncate` — call
|
||||
the corresponding SX numeric primitives.
|
||||
- [ ] `Fractional` typeclass stub: `(/)`, `recip`, `fromRational`.
|
||||
- [x] `Fractional` typeclass stub: `(/)`, `recip`, `fromRational`. _(/)
|
||||
already a binop; `recip x = 1 / x` and `fromRational x = x` registered as
|
||||
builtins in the post-prelude block._
|
||||
- [ ] `Floating` typeclass stub: `pi`, `exp`, `log`, `sin`, `cos`, `(**)`
|
||||
(power operator, maps to SX exponentiation).
|
||||
- [ ] Tests in `lib/haskell/tests/numeric.sx` (≥ 15 tests: fromIntegral
|
||||
@@ -301,6 +303,10 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
||||
|
||||
_Newest first._
|
||||
|
||||
**2026-05-07** — Phase 10 Fractional stub (recip, fromRational):
|
||||
- `(/)` already a binop. Added `recip` and `fromRational` as builtins
|
||||
post-prelude. 3 new tests in `numerics.sx` (now 31/31).
|
||||
|
||||
**2026-05-07** — Phase 10 math builtins (sqrt/floor/ceiling/round/truncate):
|
||||
- Inserted in the post-prelude `begin` block so they override the prelude's
|
||||
identity stubs. `ceiling` is the only one needing a definition (SX doesn't
|
||||
|
||||
Reference in New Issue
Block a user