Replace all fromIntegral with unwitch conversions#210
Merged
jappeace merged 5 commits intojappeace:masterfrom Apr 20, 2026
Merged
Replace all fromIntegral with unwitch conversions#210jappeace merged 5 commits intojappeace:masterfrom
jappeace merged 5 commits intojappeace:masterfrom
Conversation
Eliminate every fromIntegral call (70+) across 20 files by using explicit unwitch conversion functions. This makes numeric type conversions self-documenting and catches unsafe casts at compile time. Conversion patterns used: - Int32 ↔ CInt: Int32.toCInt / CInt.toInt32 (total) - CInt → Int: CInt.toInt (total, for IntMap keys and BS lengths) - Int → CInt: Int.toCInt with maybe 0 id (partial) - Int → Word8: Int.toWord8 with maybe 0 id (partial, hex parsing) - Word8 → Int/Double: Word8.toInt / Word8.toDouble (total) - Int32 → Int (IntMap keys): CInt.toInt . Int32.toCInt (total chain, avoids Int32.toInt which returns Maybe due to Haskell spec) - Int32/CInt → Double: Int32.toDouble / CInt.toDouble (total) Added unwitch 2.2.0 to cabal deps (library, test-suite, redraw-demo) and to both nix overlays (hpkgs.nix for native, cross-deps.nix for Android cross-compilation). Prompt: replace all primitive conversions in hatter with unwitch Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
iOS and watchOS use ios-deps.nix (native macOS GHC) rather than cross-deps.nix (Android cross-GHC). The unwitch package was missing from the iOS/watchOS haskellPackages overlay, causing "Could not find module Unwitch.Convert.*" errors in CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mkIOSLib compiles hatter with raw ghc -staticlib, not through cabal, so its non-boot dependencies must be explicitly provided in the crossDeps package DB. Before unwitch, hatter only used GHC boot packages (base, containers, text, etc.). Now it also needs unwitch. Add hatterOwnDeps list to ios-deps.nix so the unwitch .a/.hi/.conf are collected even when no consumerCabalFile is provided (as in CI). This fixes iOS and watchOS builds which both use ios-deps.nix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
collect-deps.nix only processes packages explicitly in its deps list — it doesn't follow propagatedBuildInputs. Since hatter's .conf now references unwitch, unwitch's .a and .conf must also be collected. Without this, Android builds fail with "unusable due to missing dependencies: unwitch-2.2.0-..." when importing Hatter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jappeace
reviewed
Apr 20, 2026
| -- Total on all GHC-supported platforms (Int >= 32 bits). | ||
| -- Uses the total chain Int32 -> CInt -> Int. | ||
| int32ToIntKey :: Int32 -> Int | ||
| int32ToIntKey = CInt.toInt . Int32.toCInt |
Owner
There was a problem hiding this comment.
unwitch 3.0.0 makes Int32.toInt total (Int32 -> Int) on GHC, so the int32ToIntKey helper and CInt.toInt . Int32.toCInt chain are no longer needed. Replace all 10 copies with direct Int32.toInt calls and remove the CInt import from files that only used it for the helper. Bump unwitch dependency to >= 3.0.0, point nix overlays to the jappeace/unwitch commit with the total conversion. Prompt: go simplify conversions here with unwitch 3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fromIntegralcalls across 20 files with explicit, type-safeunwitchconversion functionsunwitch >= 2.2.0as a dependency to library, test-suite, and redraw-demo cabal stanzashpkgs.nixand Android cross-compilationcross-deps.nix)Conversion patterns
Int32.toCIntCInt.toInt32CInt.toIntInt.toCIntInt.toWord8Word8.toIntWord8.toDoubleCInt.toInt . Int32.toCIntInt32.toDoubleTest plan
cabal build— all 24 modules compile, no warningscabal test— all tests passnix-build nix/ci.nix -A native— passesgrep -r fromIntegral src/ test/— zero matches confirmed🤖 Generated with Claude Code