hearth-def-caching

Cache method bodies with ValDefsCache for type-class instance derivation.

68|7|Updated Nov 24, 2025
One-click install
npx skills add https://github.com/kubuszok/kindlings --skill hearth-def-caching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hearth-def-caching
Source: https://github.com/kubuszok/kindlings/tree/main/docs/contributing/hearth-def-caching
Command: npx skills add https://github.com/kubuszok/kindlings --skill hearth-def-caching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a robust pattern for generating type-class instances where bodies should be derived once and reused across multiple methods, enabling safe sharing of derived definitions in complex derivations.

Core Features & Use Cases

  • Single shared ValDefsCache across multiple methods to avoid duplication and maintain consistency.
  • forwardDeclare + buildCachedWith to materialize cached defs under controlled scope.
  • toValDefs.use hoisting to emit top-level defs alongside the final instance, enabling scalable multi-method derivations and recursive structures.

Quick Start

Use this skill to implement a multi-method type-class instance with cached bodies across methods.

Frequently Asked Questions about hearth-def-caching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cache derived type-class instances in Scala to avoid recomputation?

To cache type-class instances in Scala and avoid recomputation, use a shared ValDefsCache across multiple methods, applying forwardDeclare and buildCachedWith to materialize cached defs under a controlled scope.

What is the best way to handle recursive type-class derivation in Scala macros?

Recursive type-class derivation in Scala macros requires forward-declaring definitions, building cached method bodies with buildCachedWith, and hoisting defs via toValDefs.use to emit top-level defs alongside the final instance.

Can I parallelize independent parts of a type-class derivation?

Yes, independent parts of type-class derivations can be parallelized using parTuple, provided you carefully match arity and wrap the output correctly via toValDefs.use to emit top-level defs.

Does cached type-class derivation work with both Scala 2 and Scala 3?

Cached type-class derivation handles Scala 2 and Scala 3 interop, allowing you to generate multi-method instances with shared ValDefsCache while maintaining safe sharing of derived definitions across complex structures.

Why does my multi-method type-class derivation duplicate method bodies?

Multi-method type-class derivation duplicates method bodies when a single shared ValDefsCache is not used, making it necessary to hoist defs via toValDefs.use to emit top-level defs and maintain consistency.