Remove Box wrapper from RESP Arr variant#4
Conversation
Array already provides heap indirection for the recursive RESP type, so the extra Box layer was unnecessary overhead. This simplifies the API by removing Box.init/Box.peek from all array construction and access patterns. Closes #1
There was a problem hiding this comment.
Build & Tests
Build: fail — the code does not compile. Both CI (macOS, Ubuntu) and local type-check fail with:
Recursive type `RESP` appears by value in member type `(Array RESP)`. Use `Ptr` or `Box`.
Once the RESP type definition is rejected, every downstream symbol becomes undefined, cascading into hundreds of errors. Tests never execute.
Findings
1. The core premise is wrong (blocking)
The PR claims "Array already provides heap indirection for the recursive type, so Box was unnecessary overhead." This is incorrect.
The Carp compiler (Validate.hs:65-82, containsSelfByValue) explicitly checks for recursive types appearing by value. Only Box, Ptr, Ref, and FuncTy are recognized as indirection boundaries that break the recursion cycle. Array is treated as a value type at the Carp type level — even though its C representation uses a heap pointer internally, the type checker recurses into Array's type variable and finds RESP inside (Array RESP), flagging it as recursive-by-value.
The Box wrapper in (Array (Box RESP)) is required by the Carp type system. Removing it is not a valid optimization — it produces a compilation error.
2. No workaround exists
Short of modifying the compiler's recursion checker (a separate, much larger effort), there is no way to have (Arr [(Array RESP)]) compile. The existing (Arr [(Array (Box RESP))]) is the intended and correct pattern for recursive sum types in Carp.
Verdict: close
The change cannot compile and the core premise is incorrect. The Box wrapper is structurally required by Carp's type system for the recursive RESP type. This PR should be closed.
|
Closing: the core premise is incorrect — Carp's type system requires Box for recursive types in Array. |
Summary
(Arr [(Array (Box RESP))])to(Arr [(Array RESP)])in the RESP type definitionBox.init/Box.peekcalls from the encoder, decoder,Redis.send, and testsCloses #1
Test plan
examples/simple.carpOpened by the carpentry-org heartbeat agent (Claude). hellerve has not reviewed this yet.