ワンクリックで
gadt-implementer
Implement Generalized Algebraic Data Types (GADTs) for expressive type-safe data structures.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Implement Generalized Algebraic Data Types (GADTs) for expressive type-safe data structures.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Implement abstract machines for defining and executing operational semantics of programming languages.
Implements alias and points-to analysis for pointer programs. Use for: (1) Optimizing compilers, (2) Verifying memory safety, (3) Program understanding, (4) Parallelization.
Define program meaning through logical assertions and proof rules (Hoare logic).
Transforms closures to explicit environments. Use when: (1) Implementing functional languages, (2) Building compilers, (3) Understanding closures.
Implements common subexpression elimination (CSE). Use when: (1) Building compilers, (2) Optimizing code, (3) Program analysis.
Implements general dataflow analysis framework. Use when: (1) Building compilers, (2) Static analysis tools, (3) Program verification.
| name | gadt-implementer |
| description | Implement Generalized Algebraic Data Types (GADTs) for expressive type-safe data structures. |
| version | 1.0.0 |
| tags | ["type-theory","data-structures","haskell","pldi"] |
| difficulty | advanced |
| languages | ["haskell","ocaml","rust"] |
| dependencies | ["type-checker-generator","simply-typed-lambda-calculus"] |
Generalized Algebraic Data Types (GADTs) extend ordinary algebraic data types by allowing constructors to have different return types, enabling more precise type indexing and type-safe encodings.
| Concept | Description |
|---|---|
| Type Index | Type parameter that tracks additional information |
| Type Refinement | Pattern matching reveals more specific types |
| Existential | Constructors can hide type arguments |
| Phantom Types | Type parameters with no runtime representation |
| Type Witnesses | Values that witness type equalities |
{-# LANGUAGE GADTs #-} or {-# LANGUAGE GADTSyntax #-} in GHCDataKinds for type-level programmingTypeApplications for disambiguationExistentialQuantification with GADTstype-checker-generator - Type checking for GADTsdependent-type-implementer - More expressive than GADTsexistential-types - Existential quantificationsimply-typed-lambda-calculus - Foundation for typed ASTs| Reference | Why It Matters |
|---|---|
| Xi, Chen & Chen, "Guarded Recursive Datatype Constructors" (POPL 2003) | Original paper introducing GADTs in ML/Haskell |
| Peyton Jones, Vytiniotis, Weirich & Shields, "Practical Type Inference for Arbitrary-Rank Types" (JFP 2007) | Type inference for GADTs and rank-N polymorphism |
| GHC User's Guide "GADTs" | Practical implementation details |
| Approach | Pros | Cons |
|---|---|---|
| GADTs | Precise types, no runtime checks | Complex type errors |
| Phantom types | Simpler | Less expressive |
| Finally tagless | No GADT syntax needed | Different style |
A high-quality implementation should have:
| Criterion | What to Look For |
|---|---|
| Type Safety | Pattern matching refines types correctly |
| Completeness | Handles all GADT features (existentials, equality) |
| Error Messages | Clear indication of type mismatches |
| Inference | Infers types where possible |
✅ Good: Type-safe evaluator with no runtime checks, clear GADT structure ⚠️ Warning: Overuses GADTs when simpler types would work ❌ Bad: GADT structure doesn't actually provide type safety benefits
GADT implementations:
| Tool | Language | What to Learn |
|---|---|---|
| GHC | Haskell | Production GADTs |
| OCaml | OCaml | GADTs |
| Rust | Rust | GADTs |
| Pitfall | Real Consequence | Solution |
|---|---|---|
| Type errors | Confusing errors | Better error messages |