Conversation
…e folding over Patterns, generalizing the learning from paraGraph
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (19 files)
Review NotesThis is a well-designed additive feature that introduces a unified scope abstraction for structure-aware folds:
No issues requiring inline comments were found. |
There was a problem hiding this comment.
Pull request overview
This PR introduces a unified, extensible “scope” abstraction for structure-aware folds in the pattern library, generalizing classic paramorphism (para) into a scope-explicit primitive (paraWithScope) while preserving existing behavior for both tree (para) and graph (paraGraph) folds.
Changes:
- Added new scope APIs in
Pattern.Core:ScopeQuery(withScopeId),TrivialScope,ScopeDict,toScopeDict, andparaWithScope; reimplementedparaviaparaWithScope. - Added graph-side generic scope reification via
scopeDictFromGraphViewand an internalGraphViewScopeadapter; updated tests to cover graph-backed scope queries and equivalence. - Updated reference docs and porting guidance to explain the unified scope model and its cross-language mapping.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
libs/pattern/src/Pattern/Core.hs |
Introduces unified scope abstractions (ScopeQuery, TrivialScope, ScopeDict) and paraWithScope; redefines para in terms of the new primitive. |
libs/pattern/src/Pattern/Graph/Transform.hs |
Adds scopeDictFromGraphView and internal GraphViewScope adapter; wires updated paraGraph/paraGraphFixed plumbing. |
libs/pattern/tests/Spec/Pattern/CoreSpec.hs |
Adds unit + property tests for TrivialScope, paraWithScope compatibility, custom scope providers, and ScopeDict equivalence. |
libs/pattern/tests/Spec/Pattern/Graph/TransformSpec.hs |
Adds tests for graph-backed generic scope answers (scopeDictFromGraphView) and wrapper-preservation tests for paraGraph/paraGraphFixed. |
libs/pattern/src/Pattern.hs |
Updates top-level module documentation to reflect new scope model and the new graph scope reifier. |
docs/reference/features/paramorphism.md |
Reframes paramorphism docs around the unified scope model and documents paraWithScope as canonical. |
docs/reference/features/para-graph.md |
Clarifies paraGraph as graph-scoped wrapper and documents scopeDictFromGraphView relationship. |
docs/reference/PORTING-GUIDE.md |
Adds explicit typeclass/dictionary ↔ trait/object mapping guidance for ports; updates fold implementation guidance. |
proposals/scope-unification-proposal.md |
Adds/updates the design proposal narrative and example code for the unified scope model. |
specs/038-scope-unification/tasks.md |
Adds implementation task breakdown for the feature. |
specs/038-scope-unification/spec.md |
Adds the feature specification (user stories, requirements, success criteria). |
specs/038-scope-unification/research.md |
Records design decisions and alternatives considered for scope unification. |
specs/038-scope-unification/quickstart.md |
Adds a quickstart checklist for implementing and verifying the feature. |
specs/038-scope-unification/plan.md |
Adds implementation plan, constraints, and testing/perf guardrails. |
specs/038-scope-unification/data-model.md |
Defines the in-memory API “data model” for scope unification concepts. |
specs/038-scope-unification/contracts/Pattern.Core.hs |
Adds contract stub for intended Pattern.Core API (currently diverges from implementation). |
specs/038-scope-unification/contracts/Pattern.Graph.Transform.hs |
Adds contract stub for intended graph-side API (currently diverges from implementation). |
specs/038-scope-unification/checklists/requirements.md |
Adds a spec-quality checklist for the feature artifacts. |
.cursor/rules/specify-rules.mdc |
Updates generated rules to include the new feature’s tech footprint. |
Align the proposal and contract artifacts with the implemented scope API, and remove unnecessary graph-scope preprocessing from paraGraph. Reject duplicate GraphView identities during generic scope reification so lookup behavior stays explicit and well-defined. Made-with: Cursor
This pull request introduces a unified and extensible scope abstraction for structure-aware folds in the Pattern library, generalizing paramorphism (
para) to support both tree and graph contexts under a common interface. The changes add new typeclasses and data types (ScopeQuery,TrivialScope,ScopeDict), provide a new generic fold primitive (paraWithScope), and update documentation throughout the codebase and guides to reflect the new model and its recommended usage in ports to other languages. Backward compatibility is preserved: the classicparaAPI and behavior remain unchanged, but are now implemented in terms of the new primitives.Key changes:
Core Library API and Implementation
ScopeQuerytypeclass, theTrivialScopedata type for subtree-only scopes, theScopeDictvalue-form for first-class scope providers, and theparaWithScopefunction for explicit, scope-aware folding. The classicparais now a wrapper overparaWithScopewithTrivialScopefor backward compatibility. (libs/pattern/src/Pattern/Core.hs,Pattern.hs) [1] [2] [3] [4] [5] [6]Documentation: Reference and Porting Guides
ScopeQuery,ScopeDict, and classic paramorphism. Clarified the recommended implementation order and tree/graph fold distinctions. (docs/reference/PORTING-GUIDE.md) [1] [2] [3] [4]docs/reference/features/paramorphism.md) [1] [2] [3] [4] [5]paraGraphdocumentation to clarify its role as a graph-scoped fold under the new scope model and to document the new internal helper for deriving aScopeDictfrom aGraphView. (docs/reference/features/para-graph.md) [1] [2] [3]Rules and Feature Plan Updates
.cursor/rules/specify-rules.mdc) [1] [2]These changes lay the groundwork for more powerful, extensible, and portable structure-aware folds, while keeping the existing API stable for current users.