A multi-library Haskell mono-repo providing tools for working with patterns, subjects, and graph structures. The primary library, pattern, offers a generalized representation of graph elements using category theory.
Prerequisites:
- GHC 9.10.3
- Cabal 3.6.2.0 or later
Using ghcup:
ghcup install ghc 9.10.3
ghcup set ghc 9.10.3
ghcup install cabal
ghcup set cabalClone with submodules (required for corpus tests):
# When cloning for the first time
git clone --recurse-submodules <repository-url>
# Or if already cloned, initialize submodules
git submodule update --init --recursiveThe corpus tests require the tree-sitter-gram submodule to be initialized at libs/gram/test-data/tree-sitter-gram. Tests will skip gracefully if the submodule is not initialized.
Add to your project:
build-depends:
- patternimport Pattern.Core (pattern, patternWith)
-- Create an atomic pattern
atomA = pattern "A"
-- Create a pattern with elements
atomB = pattern "B"
relationship = patternWith "knows" [atomA, atomB]# Convert Gram notation to canonical JSON
gramref parse pattern.gram --format json --value-only --canonical
# Bidirectional conversion: Gram ↔ JSON
gramref convert pattern.json --from json --to gram
# Generate JSON Schema
gramref schema --format json-schema > pattern-schema.json
# Generate TypeScript types
gramref schema --format typescript > pattern.ts
# Generate Rust types
gramref schema --format rust > pattern.rs- User Documentation - Complete user guide with examples
- Reference Documentation - For language porters
- Canonical JSON Format - JSON format specification with examples
- User Documentation:
docs/- User-facing guides and API documentation- Pattern Construction Functions - Guide to
point,pattern, andpurewith porting guidance - Gram Serialization - Serialization, JSON, and schema generation
- Pattern Construction Functions - Guide to
- Design Documentation:
design/DESIGN.md- Category-theoretic framework and design principles - Implementation Roadmap:
TODO.md- Planned features and implementation phases - Feature Specifications:
specs/- Detailed specifications for each feature - API Documentation: Generate with
cabal haddockor seespecs/*/contracts/type-signatures.md - Quickstart Guide:
specs/002-basic-pattern-type/quickstart.md
Run the full test suite:
cabal test allImportant Test Requirements:
- JSON Roundtrip Tests: All patterns must successfully roundtrip through JSON serialization (
gram:test:gram-test --match=Roundtrip) - Corpus Tests: Require
tree-sitter-gramsubmodule initialized (tests skip gracefully if not present) - Property-Based Tests: QuickCheck validates 100+ random patterns for structural integrity
pattern: Core pattern data structure library (recursive, decorated sequences)subject: Special data structure with index, labels, and property recordgram: Serialization/deserialization for "Subject Patterns"- Gram notation (text) serialization
- Canonical JSON with bidirectional conversion
- JSON Schema generation (Draft 2020-12)
- TypeScript and Rust type generation for downstream ports
gram-hs/
├── libs/
│ ├── pattern/ # Pattern library
│ ├── subject/ # Subject library
│ └── gram/ # Gram library
├── docs/
│ ├── guide/ # User-facing documentation
│ └── reference/ # Porter-facing documentation
└── apps/
└── gram-hs-cli/ # CLI tool for testing and validation
- Typeclass Instances: Show ✅, Eq ✅, Functor ✅, Foldable ✅, Traversable (Phase 2-6)
- Constructor Functions:
point(atomic) andpattern(with elements) (Phase 3) - Classification Functions:
isNode,isRelationship,isSubgraph,isPath(Phase 8-11) - Navigation Functions:
source,target,nodes,relationships(Phase 12) - Graph Views:
GraphViewtypeclass and implementations (Phase 15) - Query Functions:
length,size,depth(Phase 7)
- Reference Implementation: Canonical reference design for translation to other languages
- Category-Theoretic Foundation: Built on solid mathematical foundations
- Schema-Lazy Design: Patterns don't commit to specific graph semantics at creation time
- Multi-Language Translation: Design prioritizes clarity and mathematical correctness
This is a reference implementation with strict quality standards. See .specify/memory/constitution.md for development principles.
Workflow Requirements:
- ALWAYS work in a feature branch - Never commit directly to
main - Use the Speckit workflow (
/speckit.specify,/speckit.plan,/speckit.tasks) - Follow the Constitution principles
BSD-3-Clause (see LICENSE file)