Skip to main content
pattern-matching Expert skill for implementing pattern matching including exhaustiveness checking, decision tree compilation, and efficient match dispatch code generation.
Ir para a instalação Skills Marketplace Descubra e explore skills de IA criadas pela comunidade.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Copiar promptMostrar detalhes do prompt Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
npx skills add https://github.com/a5c-ai/babysitter --skill pattern-matchingO comando permanece em uma só linha. Role horizontalmente para revisá-lo antes de copiar.
Prefere uma cópia local? Baixe os arquivos disponíveis atualmente no SkillsMP.
Baixar Zip Baixando... Ocupações relacionadas SOC
Baseado na classificação ocupacional SOC
Mais deste repositório Reference for querying the Atlas knowledge graph through its MCP tools — the SECONDARY enrichment/comparison layer that adds best-practice context to systems you have ALREADY scanned from your real sources (`az`, repos, dirs). Use when you need to look up nodes, edges, kinds, clusters, stats, or wiki pages in Atlas to compare against your real inventory. (atlas graph, query atlas, atlas mcp, search the graph, graph neighbors, atlas record, atlas kinds, enrichment layer)
Atlas turns your STATED NEED into a real systems atlas by SCANNING your actual sources (Azure via `az`, git repos, local dirs) and process/data mining them, THEN enriching against the Atlas knowledge graph. Use this skill when asked to inventory/map your real systems, scan your cloud + repos + directories, mine the real processes or data they contain, or collect their real constraints/gotchas. (atlas, scan my systems, inventory our azure account, map my repos, real systems atlas, process mining, data mining, collect nuances, system discovery)
assimilate-popular-workflows This skill should be used when the user asks to "find skills in the wild", "assimilate popular workflows", "discover SKILL.md files in repos", "research external skills", "find workflow patterns", "survey the skill landscape", "what skills exist out there", or wants to investigate public repositories for extractable processes, babysitter plugins, and reusable procedural insights. Searches GitHub for SKILL.md files, classifies repos by archetype, and maintains structured research under docs/reference-repos/.
Explorador de arquivos
2 arquivos name pattern-matching description Expert skill for implementing pattern matching including exhaustiveness checking, decision tree compilation, and efficient match dispatch code generation. allowed-tools Read, Write, Edit, Bash, Glob, Grep graph {"domains":["domain:software-engineering"],"specializations":["specialization:programming-languages"],"skillAreas":["skill-area:compiler-implementation","skill-area:language-design"],"roles":["role:backend-engineer"]}
Pattern Matching Skill
Implement pattern matching for programming languages including exhaustiveness checking, usefulness analysis, and efficient compilation to decision trees.
Capabilities
Parse pattern syntax (constructor, wildcard, binding, literals)
Implement exhaustiveness and usefulness checking
Compile patterns to decision trees
Implement guard clause handling
Design or-patterns and as-patterns
Implement nested pattern matching
Optimize pattern match coverage
Generate efficient match dispatch code
Usage
Invoke this skill when you need to:
Add pattern matching to a language
Implement exhaustiveness checking
Compile patterns efficiently
Handle complex pattern features
Inputs
patternTypes array Yes Types of patterns to support targetLanguage string Yes Language for implementation compilationStrategy string No Strategy (decision-tree, backtracking) features array No Advanced features to implement
Pattern Types {
"patternTypes" : [
"wildcard" ,
"variable" ,
"literal" ,
"constructor" ,
"tuple" ,
"record" ,
"list" ,
"or-pattern" ,
"as-pattern" ,
"guard"
]
}
Feature Options {
"features" : [
"exhaustiveness-checking" ,
"usefulness-checking" ,
"decision-tree-compilation" ,
"guard-clauses" ,
"nested-patterns" ,
"view-patterns" ,
"active-patterns"
]
}
Output Structure pattern-matching/
├── syntax/
│ ├── pattern.grammar # Pattern syntax
│ └── match-expr.grammar # Match expression syntax
├── analysis/
│ ├── exhaustiveness.ts # Exhaustiveness checker
│ ├── usefulness.ts # Usefulness/redundancy checker
│ └── pattern-types.ts # Pattern type inference
├── compilation/
│ ├── decision-tree.ts # Decision tree builder
│ ├── code-generator.ts # Code generation
│ └── optimizer.ts # Pattern optimization
├── runtime/
│ ├── matcher.ts # Runtime matching (interpreter)
│ └── guards.ts # Guard evaluation
└── tests/
├── exhaustiveness.test.ts
├── compilation.test.ts
└── runtime.test.ts
Pattern Syntax
type Pattern =
| { type : 'wildcard' }
| { type : 'variable' ; name : string }
| { type : 'literal' ; value : Literal }
| { type : 'constructor' ; name : string ; args : Pattern [] }
| { type : 'tuple' ; elements : Pattern [] }
| { type : 'record' ; fields : Map <string , Pattern > }
| { type : 'list' ; elements : Pattern []; rest ?: Pattern }
| { type : 'or' ; patterns : Pattern [] }
| { type : 'as' ; pattern : Pattern ; name : string }
| { type : 'guard' ; pattern : Pattern ; guard : Expr };
interface MatchExpr {
scrutinee : Expr ;
arms : MatchArm [];
}
interface MatchArm {
pattern : Pattern ;
guard ?: Expr ;
body : Expr ;
}
Exhaustiveness Checking
type PatternMatrix = Pattern [][];
function isExhaustive (matrix : PatternMatrix , types : Type [] ): boolean {
if (matrix.length === 0 ) return false ;
if (types.length === 0 ) return true ;
const firstCol = matrix.map (row => row[0 ]);
const sigma = getConstructorSignature (types[0 ]);
if (sigma.isComplete (firstCol)) {
return sigma.constructors .every (ctor =>
isExhaustive (specialize (matrix, ctor), specializationTypes (types, ctor))
);
} else {
return isExhaustive (defaultMatrix (matrix), types.slice (1 ));
}
}
function findUncoveredCase (matrix : PatternMatrix , types : Type [] ): Pattern [] | null {
if (matrix.length === 0 ) {
return types.map (generateWildcard);
}
if (types.length === 0 ) return null ;
const sigma = getConstructorSignature (types[0 ]);
const firstCol = matrix.map (row => row[0 ]);
if (sigma.isComplete (firstCol)) {
for (const ctor of sigma.constructors ) {
const witness = findUncoveredCase (
specialize (matrix, ctor),
specializationTypes (types, ctor)
);
if (witness) {
return [applyConstructor (ctor, witness.slice (0 , ctor.arity )), ...witness.slice (ctor.arity )];
}
}
return null ;
} else {
const missing = sigma.constructors .find (c => !firstCol.some (p => matchesCtor (p, c)));
if (missing) {
return [generatePattern (missing), ...types.slice (1 ).map (generateWildcard)];
}
return findUncoveredCase (defaultMatrix (matrix), types.slice (1 ));
}
}
Decision Tree Compilation
type DecisionTree =
| { type : 'fail' }
| { type : 'leaf' ; bindings : Map <string , Access >; body : Expr }
| { type : 'switch' ; access : Access ; cases : SwitchCase []; default ?: DecisionTree };
interface SwitchCase {
constructor : Constructor ;
tree : DecisionTree ;
}
interface Access {
root : string ;
path : AccessStep [];
}
type AccessStep =
| { type : 'field' ; index : number }
| { type : 'deref' };
function compilePatterns (arms : MatchArm [], scrutinee : Access ): DecisionTree {
if (arms.length === 0 ) return { type : 'fail' };
const column = selectColumn (arms);
const groups = groupByConstructor (arms, column);
if (groups.size === 0 ) {
const bindings = extractBindings (arms[0 ].pattern , scrutinee);
return { type : 'leaf' , bindings, body : arms[0 ].body };
}
const cases : SwitchCase [] = [];
for (const [ctor, ctorArms] of groups) {
const specializedAccess = extendAccess (scrutinee, ctor);
cases.push ({
constructor : ctor,
tree : compilePatterns (specializeArms (ctorArms, ctor), specializedAccess)
});
}
const defaultArms = arms.filter (arm => isWildcard (arm.pattern , column));
const defaultTree = defaultArms.length > 0
? compilePatterns (defaultArms, scrutinee)
: undefined ;
return { type : 'switch' , access : scrutinee, cases, default : defaultTree };
}
Guard Clause Handling
interface GuardedArm {
pattern : Pattern ;
guard : Expr | null ;
body : Expr ;
}
function exhaustivenessWithGuards (arms : GuardedArm [], types : Type [] ): Warning [] {
const warnings : Warning [] = [];
const unguardedMatrix = arms.map (arm => [arm.pattern ]);
if (!isExhaustive (unguardedMatrix, types)) {
warnings.push ({
type : 'possibly-non-exhaustive' ,
message : 'Match may not be exhaustive (guards present)' ,
suggestion : 'Consider adding a catch-all pattern'
});
}
return warnings;
}
type GuardedTree =
| { type : 'fail' }
| { type : 'guard' ; test : Expr ; success : GuardedTree ; failure : GuardedTree }
| { type : 'leaf' ; bindings : Map <string , Access >; body : Expr }
| { type : 'switch' ; access : Access ; cases : SwitchCase []; default ?: GuardedTree };
Code Generation
function generateCode (tree : DecisionTree , target : CodeTarget ): Code {
switch (tree.type ) {
case 'fail' :
return target.emitMatchFailure ();
case 'leaf' :
const setup = Array .from (tree.bindings .entries ())
.map (([name, access] ) => target.emitBinding (name, access));
return target.emitBlock ([...setup, target.emitExpr (tree.body )]);
case 'switch' :
return target.emitSwitch (
target.emitAccess (tree.access ),
tree.cases .map (c => ({
test : target.emitConstructorTest (c.constructor ),
body : generateCode (c.tree , target)
})),
tree.default ? generateCode (tree.default , target) : target.emitMatchFailure ()
);
}
}
function emitRustMatch (tree : DecisionTree ): string {
}
Or-Patterns and As-Patterns
function expandOrPattern (pattern : Pattern ): Pattern [] {
if (pattern.type === 'or' ) {
return pattern.patterns .flatMap (expandOrPattern);
}
return [pattern];
}
function handleAsPattern (
pattern : AsPattern ,
access : Access ,
bindings : Map <string , Access >
): void {
bindings.set (pattern.name , access);
extractBindings (pattern.pattern , access, bindings);
}
Workflow
Define pattern syntax - Grammar for patterns
Implement pattern parser - Parse patterns to AST
Build exhaustiveness checker - Matrix-based analysis
Add usefulness checker - Detect redundant patterns
Implement decision tree compilation - Efficient matching
Generate target code - From decision trees
Handle guards - Conservative guard analysis
Write tests - Exhaustiveness, compilation, runtime
Best Practices Applied
Conservative exhaustiveness with guards
Informative non-exhaustiveness witnesses
Efficient decision tree compilation
Proper binding extraction order
Support for nested patterns
Clear redundancy warnings
References
Target Processes
pattern-matching-implementation.js
parser-development.js
code-generation-llvm.js
interpreter-implementation.js