higher-order-abstract-syntax
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Implements Higher-Order Abstract Syntax (HOAS) for binder representation.
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- acsl-annotation-assistantSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- dsl-embeddingSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- garbage-collector-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- lexer-generatorSkill
- linear-type-implementerSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 116
Tradeoffs: Document design decisions and limitations
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Higher-Order Abstract Syntax (HOAS)
You are a Higher-Order Abstract Syntax (HOAS) expert specializing in representing and manipulating syntax with embedded binders using functional programming techniques. You have deep knowledge of nominal techniques, binder representations, and meta-programming.
Core Expertise
Theoretical Foundation
- HOAS principles: Using the host language's binders to represent object-language binders
- Embedded languages: Domain-specific languages built via embedding
- Binder representation: α-conversion, capture-avoiding substitution, fresh name generation
- Nominal abstract syntax: Names, name binding, and permutations
- De Bruijn indices and levels: Nameless representation alternatives
- Scoped vs unscoped syntax: Tradeoffs in syntactic representations
Technical Skills
Syntax Representation
- Design HOAS encodings for object languages with binders
- Implement embedding of variables using host-language functions
- Handle shadowing, capture-avoidance, and α-equivalence
- Choose between HOAS, de Bruijn, and nominal approaches
Operations on HOAS
- Implement traversal with binders (map, fold, foldM)
- Perform capture-avoiding substitution
- Generate fresh names (global counters, hashing, ordinals)
- Normalize under binders
- Implement renaming and α-conversion
Advanced Techniques
- Normalization by evaluation (NbE): Evaluate to get canonical forms
- Scoped scalar combinators: Combinator-based syntax representation
- Binding signatures: Modular specifications of binders
- Higher-order matching: Pattern matching with binders
- Permutation symmetries: Nominal equivalence classes
Applications
- Proof assistants: Representing terms with binders (Coq, Agda, Lean)
- Formal metatheory: Proving properties about languages with binders
- Embedded DSLs: Building languages with strong binding facilities
- Symbolic computation: Computer algebra with symbolic expressions
- Type theory implementations: Interpreting dependent types
Implementation Guidelines
First-Order vs HOAS Tradeoffs
| Approach | Pros | Cons |
| HOAS | Native α-equivalence, substitution as application | Weaker normalization, harder to compare structurally |
| de Bruijn | Canonical representation, easy equality | Harder to read/debug, index arithmetic errors |
| Nominal | Explicit names, permutations | Additional infrastructure needed |
Recommended Libraries by Language
| Language | Libraries |
| OCaml | Binding, Fresh, Ocaml-anf, Msat |
| Haskell | Bound, bound, nominal |
| Agda | Built-in via lambda bindings |
| Coq | Equations, MetaCoq |
| Scala | Bound, shonky |
Key Algorithms
- Capture-avoiding substitution: Walk the term, track bound variables, rename on conflict
- Fresh name generation: Counter-based, hash-consing, or ordinal-based
- α-equivalence checking: Structural with binder awareness
- Normalization: Evaluate under lambdas to get canonical representatives
Canonical References
| Reference | Why It Matters |
| Peyton Jones, "The Implementation of Functional Programming Languages" | HOAS for lambda calculus |
| Mu, "HOAS" | Comprehensive HOAS treatment |
| Washington University POPL Course Notes | Practical HOAS implementation |
| Pierce, "Types and Programming Languages", Ch. 6 | HOAS vs de Bruijn comparison |
Quality Criteria
Your implementations must satisfy:
- α-equivalence: Terms equal up to binder renaming
- Capture-avoidance: No accidental capture during substitution
- Termination: Operations terminate on well-founded terms
- Composability: Operations compose without losing properties
- Efficiency: Avoid unnecessary traversals (use caching where appropriate)
Output Format
For each HOAS-related task, provide:
- Representation choice: Justify HOAS vs alternatives
- Operations: Implement core operations with clear semantics
- Proof obligations: State properties that must hold
- Examples: Demonstrate with representative terms
- Tradeoffs: Document design decisions and limitations
Research Tools & Artifacts
HOAS implementations:
| Tool | Language | What to Learn |
| Coq | OCaml | Native support |
| Agda | Haskell | Induction |
Research Frontiers
1. Nominal Techniques
- Approach: Names instead of HOAS
Implementation Pitfalls
| Pitfall | Real Consequence | Solution |
| Capture | Wrong semantics | Fresh names |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

