| name | categorical-structure-builder |
| description | Universal template for implementing categorical structures in meta-prompting frameworks. Applies to functors, monads, comonads, natural transformations, adjunctions, hom-equivalences, limits, colimits, and enriched categories. Use when extending frameworks with new categorical constructs. |
Categorical Structure Builder
A universal template for implementing any categorical structure as a command or skill in a meta-prompting framework.
Purpose
This skill provides a generalized template that can instantiate:
- Functors (F: C → D)
- Monads (M: C → C with unit, bind, join)
- Comonads (W: C → C with extract, duplicate, extend)
- Natural Transformations (α: F ⇒ G)
- Adjunctions (F ⊣ G)
- Hom-Equivalences (Hom(F(A), B) ≅ Hom(A, G(B)))
- Limits and Colimits
- Enriched Categories ([0,1], Ab, Cat)
Universal Structure Template
Core Pattern
Every categorical structure implementation follows this pattern:
┌─────────────────────────────────────────────────────────────────────────────┐
│ CATEGORICAL STRUCTURE: {structure_name} │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ FORMAL DEFINITION: │
│ {formal_type_signature} │
│ │
│ OPERATIONS: │
│ {operation_1}: {type_signature_1} ({description_1}) │
│ {operation_2}: {type_signature_2} ({description_2}) │
│ ... │
│ │
│ LAWS: │
│ 1. {law_name_1}: {law_statement_1} │
│ 2. {law_name_2}: {law_statement_2} │
│ ... │
│ │
│ COMMAND SYNTAX: │
│ /{command} @mode:{operation} @{param}:{value} "task" │
│ │
│ COMPOSITION INTEGRATION: │
│ With →: {sequential_behavior} │
│ With ||: {parallel_behavior} │
│ With ⊗: {tensor_behavior} │
│ With >=>: {kleisli_behavior} │
│ │
│ QUALITY PROPAGATION: │
│ {quality_rule} │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
Instantiation Templates
Template 1: Functor
CATEGORICAL STRUCTURE: Functor {name}
FORMAL DEFINITION:
F: C → D
- F_obj: Obj(C) → Obj(D)
- F_mor: Mor(C) → Mor(D)
OPERATIONS:
map: (A → B) → F(A) → F(B)
LAWS:
1. Identity: F(id_A) = id_{F(A)}
2. Composition: F(g ∘ f) = F(g) ∘ F(f)
COMMAND SYNTAX:
/{name} @input:{source_type} @output:{target_type} "task"
COMPOSITION INTEGRATION:
With →: F(A → B) composes as F(A)
Example Instantiation - Route Functor:
CATEGORICAL STRUCTURE: Functor Route
FORMAL DEFINITION:
F_route: Task → Prompt
OPERATIONS:
map: (Task → Task') → (Prompt → Prompt')
LAWS:
1. Identity: route(trivial_task) = trivial_prompt
2. Composition: route(task_B ∘ task_A) = route(task_B) ∘ route(task_A)
COMMAND SYNTAX:
/route "task description"
Template 2: Monad
CATEGORICAL STRUCTURE: Monad {name}
FORMAL DEFINITION:
M: C → C (endofunctor with extra structure)
- unit: A → M(A)
- bind: M(A) → (A → M(B)) → M(B)
- join: M(M(A)) → M(A)
OPERATIONS:
unit: A → M(A)
bind: M(A) × (A → M(B)) → M(B)
join: M(M(A)) → M(A)
fmap: (A →
Example Instantiation - RMP Monad:
CATEGORICAL STRUCTURE: Monad RMP
FORMAL DEFINITION:
M_RMP: Prompt → Prompt (iterative refinement)
OPERATIONS:
unit: prompt → MonadPrompt(prompt, quality=initial)
bind: MonadPrompt × improve → MonadPrompt'
join: MonadPrompt(MonadPrompt(p)) → MonadPrompt(p)
COMMAND SYNTAX:
/rmp @quality:0.85 @max_iterations:5 "task"
Template 3: Comonad
CATEGORICAL STRUCTURE: Comonad {name}
FORMAL DEFINITION:
W: C → C (endofunctor, dual to monad)
- extract: W(A) → A
- duplicate: W(A) → W(W(A))
- extend: (W(A) → B) → W(A) → W(B)
OPERATIONS:
extract: W(A) → A
duplicate: W(A) → W(W(A))
extend: (W(A) → B) → W(A) → W(B)
fmap: (A → B) →
Example Instantiation - Context Comonad:
CATEGORICAL STRUCTURE: Comonad Context
FORMAL DEFINITION:
W_ctx: History → Context
OPERATIONS:
extract: History → FocusedContext
duplicate: History → History(History)
extend: (History → Summary) → History → History(Summary)
COMMAND SYNTAX:
/context @mode:extract @focus:recent @depth:3 "task"
/context @mode:duplicate "create meta-observation"
/context @mode:extend @transform:summarize "apply to context"
Template 4: Natural Transformation
CATEGORICAL STRUCTURE: Natural Transformation {name}
FORMAL DEFINITION:
α: F ⇒ G (transformation between functors)
- α_A: F(A) → G(A) for each object A
OPERATIONS:
transform: F(A) → G(A)
NATURALITY CONDITION:
For all f: A → B:
α_B ∘ F(f) = G(f) ∘ α_A
Diagram:
F(A) ──F(f)──▶ F(B)
│ │
α_A α_B
▼ ▼
G(A) ──G(f)──▶ G(B)
LAWS:
1. Naturality: α_B ∘ F(f)
Example Instantiation - Strategy Transform:
CATEGORICAL STRUCTURE: Natural Transformation StrategySwitch
FORMAL DEFINITION:
α: F_ZeroShot ⇒ F_ChainOfThought
OPERATIONS:
transform: ZeroShotPrompt → ChainOfThoughtPrompt
NATURALITY:
Switching strategy then applying to task =
Applying to task then switching strategy
COMMAND SYNTAX:
/transform @from:zero-shot @to:chain-of-thought "task"
Template 5: Adjunction
CATEGORICAL STRUCTURE: Adjunction {name}
FORMAL DEFINITION:
F ⊣ G (F left adjoint to G)
- F: C → D (left adjoint / free)
- G: D → C (right adjoint / forgetful)
- unit: η: Id_C ⇒ G∘F
- counit: ε: F∘G ⇒ Id_D
HOM-SET ISOMORPHISM:
Hom_D(F(A), B) ≅ Hom_C(A, G(B))
This is natural in both A and B.
OPERATIONS:
left_adjoint: A →
Example Instantiation - Task-Prompt Adjunction:
CATEGORICAL STRUCTURE: Adjunction TaskPrompt
FORMAL DEFINITION:
F_gen ⊣ G_extract
- F_gen: Task → Prompt (generate prompt from task)
- G_extract: Prompt → Task (extract task from prompt)
HOM-SET ISOMORPHISM:
Hom(GeneratedPrompt, TargetPrompt) ≅ Hom(Task, ExtractedTask)
COMMAND SYNTAX:
/adjoint @mode:free "generate prompt from task"
/adjoint @mode:forget "extract task from prompt"
Template 6: Hom-Equivalence
CATEGORICAL STRUCTURE: Hom-Equivalence {name}
FORMAL DEFINITION:
Natural isomorphism of hom-sets:
Hom_D(F(A), B) ≅ Hom_C(A, G(B))
This is the core of adjunctions, but can exist independently.
OPERATIONS:
forward: Hom(F(A), B) → Hom(A, G(B))
backward: Hom(A, G(B)) → Hom(F(A), B)
LAWS:
1. Inverse: φ⁻¹ ∘ φ = id, φ ∘ φ⁻¹ = id
2. Naturality: Commutes with composition in both arguments
DIAGRAM:
Hom(F(A), B) ──────φ──────▶
Template 7: Enriched Category
CATEGORICAL STRUCTURE: Enriched Category {name} over {V}
FORMAL DEFINITION:
Category C enriched over monoidal category V
- Objects: Obj(C)
- Hom-objects: Hom(A,B) ∈ V (not just sets!)
- Composition: Hom(B,C) ⊗ Hom(A,B) → Hom(A,C)
- Identity: I_V → Hom(A,A)
ENRICHMENT BASE V:
[0,1]-enriched: Hom-objects are quality scores
Ab-enriched: Hom-objects are abelian groups
Cat-enriched: Hom-objects are categories (2-categories)
OPERATIONS:
hom: (A,
[,]
Example Instantiation - Quality-Enriched Prompts:
CATEGORICAL STRUCTURE: Enriched Category QualityPrompts over [0,1]
FORMAL DEFINITION:
Prompts enriched over ([0,1], min, 1)
OPERATIONS:
hom(A, B) = quality(A → B) ∈ [0,1]
compose(q1, q2) = min(q1, q2)
id = 1.0
COMMAND SYNTAX:
/quality @hom:prompt_A,prompt_B "assess transformation quality"
Usage Protocol
Step 1: Identify the Categorical Structure
Question: What structure am I implementing?
□ Functor - Preserves structure between categories
□ Monad - Computation with effects/context
□ Comonad - Context-dependent computation
□ Nat. Trans. - Transformation between functors
□ Adjunction - Pair of functors with universal property
□ Hom-Equiv. - Isomorphism of hom-sets
□ Enriched - Hom-objects with extra structure
□ Limit - Universal cone
□ Colimit - Universal cocone
□ Other - Use general template
Step 2: Instantiate the Template
1. Fill in FORMAL DEFINITION with types
2. List all OPERATIONS with signatures
3. State LAWS precisely
4. Design COMMAND SYNTAX following unified pattern
5. Define COMPOSITION behavior with all operators
6. Specify QUALITY propagation rule
Step 3: Verify Laws
For each law:
1. Write property-based test
2. Generate test cases
3. Verify law holds
4. Document verification
Step 4: Integrate with Framework
1. Create command file in .claude/commands/
2. Update ORCHESTRATION-SPEC.md
3. Update meta-self skill
4. Add to CLAUDE.md command table
5. Create integration tests
Quick Reference Card
┌─────────────────────────────────────────────────────────────────────────────┐
│ CATEGORICAL STRUCTURE QUICK REFERENCE │
├──────────────┬──────────────────┬───────────────────────────────────────────┤
│ Structure │ Key Operations │ Core Law │
├──────────────┼──────────────────┼───────────────────────────────────────────┤
│ Functor │ map │ F(g∘f) = F(g)∘F(f) │
│ Monad │ unit, bind, join │ (m >>= f) >>= g = m >>= (x. f(x) >>= g) │
│ Comonad │ extract, extend │ extract ∘ duplicate = id │
│ Nat. Trans. │ transform │ α_B ∘ F(f) = G(f) ∘ α_A │
│ Adjunction │ unit, counit │ (ε_F)∘(F_η) = id_F │
│ Hom-Equiv. │ forward, back │ φ⁻¹ ∘ φ = id │
│ Enriched │ hom, compose │ Associativity in V │
└──────────────┴──────────────────┴───────────────────────────────────────────┘
Example: Applying Template to New Structure
Task: Add Kan Extension to the framework
Step 1: Identify → This is a universal construction (limit in functor category)
Step 2: Instantiate
CATEGORICAL STRUCTURE: Left Kan Extension
FORMAL DEFINITION:
Lan_K(F): D → E
Given K: C → D and F: C → E, find universal Lan_K(F): D → E
Unit: F ⇒ Lan_K(F) ∘ K
OPERATIONS:
extend: F → Lan_K(F)
unit: F(A) → Lan_K(F)(K(A))
LAWS:
Universal Property:
For any G: D → E with α: F ⇒ G∘K,
there exists unique β: Lan_K(F) ⇒ G such that
β_K ∘
Version
Skill Version: 1.0
Framework Compatibility: 2.0+
Categorical Coverage: Functor, Monad, Comonad, NT, Adjunction, Hom-Equiv, Enriched
Extensible: Yes - use template pattern for new structures