# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Build Commands ```bash cabal build # Build the project cabal test # Run all tests cabal repl # Start interactive REPL ``` To run a single test file or specific test: ```bash cabal test --test-option=--match="/DatalogParser/" ``` ## Architecture This is an experimental Datalog implementation in Haskell with the following components: ### Parsing Layer (`src/Datalog/DatalogParser.hs`) Megaparsec-based parser that converts Datalog text into an AST: - `Term` - Variables (`Var`), symbols (`Sym`), numbers (`Num`) - `Literal` - Predicate with arguments, optionally negated - `Statement` - Fact, Rule (with `Head` and body literals), or Query - Entry points: `parseDatalog`, `parseDatalogFile` ### Evaluation Engine (`src/Datalog/InMemoryDB.hs`) In-memory database storing relations and rules: - `InMemoryDB` - Contains `relations` map and `constants` set (Herbrand universe) - `Relation` - Name, arity, tuples (facts), and associated rules - `RelationRule` - Head variables and body constraints - Key functions: `withFacts`, `withFactsAndRules` for building databases - Query evaluation is not yet implemented ### Data Flow 1. Text parsed into `Statement` (Fact/Rule/Query) 2. Facts populate relations with tuples; rules encode derivation logic via `RuleContext` and `BodyConstraint` 3. Variables are indexed during rule processing for efficient constraint matching ### Other Modules - `SimpleParser` / `ArithmeticParser` - Experimental arithmetic expression parsers - `Ologs` - Categorical data structures (dots and arcs representing objects and morphisms) ## Development Environment Nix support via `shell.nix` provides HLS, cabal-install, and Hoogle. Use `direnv allow` for automatic environment loading.