agentleFS
rainoftimerainoftime/pl-skills/existential-types/SKILL.md

existential-types

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Implement existential types for data abstraction and hiding type information.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    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
  1. Distinctive:

    Type Erasure: Remove type information at boundaries

    line 28
  2. Distinctive:

    Use GADTs for existential types in Haskell

    line 43
  3. Distinctive:

    Use continuation-passing for rank-2 types

    line 47
  4. Distinctive:

    When concrete types are known (use direct types)

    line 84
  5. Distinctive:

    When performance is critical (boxing overhead)

    line 86

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Existential Types

Existential types (∃α.τ) hide a type variable within a type, enabling data abstraction and the creation of heterogeneous collections. They are the dual of universal types (∀α.τ) in System F.

When to Use This Skill

  • Implementing abstract data types (ADTs)
  • Creating heterogeneous collections
  • Building type-erased interfaces
  • Implementing dynamic dispatch patterns
  • Hiding implementation details

What This Skill Does

  1. Existential Quantification: Hide type variables in data types
  2. Type Abstraction: Expose operations without revealing implementation type
  3. Witness Types: Package a type with operations on that type
  4. Type Erasure: Remove type information at boundaries
  5. Dynamic Typing: Recover type information when needed

Key Concepts

ConceptDescription
Existential Quantification∃α.τ - there exists some type α such that τ
Type HidingInternal type not exposed to external observers
PackageValue bundled with operations
Abstract TypeType known only by its operations
Dual of Universal∃α.τ ≈ ∀β.(∀α.τ→β)→β

Tips

  • Use GADTs for existential types in Haskell
  • Existentials correspond to interfaces/protocols in OOP
  • Think of them as "some type T, we don't know which"
  • Combine with type classes for operation bundles
  • Use continuation-passing for rank-2 types

Common Use Cases

  • Abstract data types (stacks, queues, maps)
  • Type-erased callbacks and handlers
  • Heterogeneous collections
  • State machines with hidden state
  • Effect handlers

Related Skills

  • system-f - Universal quantification (∀)
  • gadt-implementer - GADTs for existentials
  • module-system - ML modules for abstraction
  • type-class-implementer - Type classes for operations

Canonical References

ReferenceWhy It Matters
Mitchell, Plotkin "Abstract types have existential type" (1988)Classic paper
Pierce "Types and Programming Languages" Ch. 24Textbook treatment
GHC User's Guide "ExistentialQuantification"Practical usage

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
GADT syntaxClean, integratedGHC specific
Explicit forallStandard HaskellMore verbose
newtype wrapperSimpleLimited flexibility

When NOT to Use This Skill

  • When concrete types are known (use direct types)
  • For simple polymorphism (use system-f)
  • When performance is critical (boxing overhead)

Limitations

  • Cannot pattern match on hidden type
  • Some runtime overhead for packaging
  • Type inference is limited

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
Type SafetyHidden type cannot escape its scope
AbstractionImplementation details are hidden
OperationsPackaged with necessary operations
CompositionCan combine existential packages

Quality Indicators

✅ Good: Clean abstraction, well-defined operations, type-safe interface ⚠️ Warning: Escapes existential scope, exposes hidden type ❌ Bad: No real abstraction, just wrapping values

Research Tools & Artifacts

Existential types in:

ToolLanguageWhat to Learn
GHCHaskellImplementation
OCamlOCamlObjects

Research Frontiers

1. Dynamic Types

  • Approach: Type erasure

Implementation Pitfalls

PitfallReal ConsequenceSolution
Type escapeViolates abstractionScope tracking

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.