fp-ts Algebraic Data Types and Type Classes

Model TypeScript domain logic with fp-ts algebraic data types and type classes.

11|3|Updated Jan 30, 2026
One-click install
npx skills add https://github.com/whatiskadudoing/fp-ts-skills --skill fp-ts-algebraic-data-types-and-type-classes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fp-ts Algebraic Data Types and Type Classes
Source: https://github.com/whatiskadudoing/fp-ts-skills/tree/main/skills/fp-algebraic-types
Command: npx skills add https://github.com/whatiskadudoing/fp-ts-skills --skill fp-ts-algebraic-data-types-and-type-classes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a practical approach to modeling domain concepts in TypeScript using algebraic data types (ADTs) and type classes, enabling safer, more expressive code.

Core Features & Use Cases

  • Product types (tuples and records) for representing data where all parts are required.
  • Sum types (discriminated unions) for modeling mutually exclusive states and workflows.
  • Type classes (Eq, Ord, Semigroup, Monoid) and utilities for flexible composition and domain modeling.
  • Real-world examples: domain modeling, API design, and validation within fp-ts.

Quick Start

Start by defining a simple ADT and a corresponding type-class instance in fp-ts, then compose it with a small domain example.

Frequently Asked Questions about fp-ts Algebraic Data Types and Type Classes

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

FAQPage Schema
How do I model complex domain logic in TypeScript using algebraic data types?

Algebraic data types model complex domain logic in TypeScript by using product types for required data and sum types for mutually exclusive states. This approach enables safe composition and reusability across codebases using fp-ts utilities.

What is the difference between product types and sum types in domain modeling?

In domain modeling, product types represent data where all parts are required, like tuples and records. Sum types, implemented as discriminated unions, model mutually exclusive states and workflows to ensure valid domain transitions.

How do I use fp-ts type classes like Eq and Monoid for TypeScript validation?

For TypeScript validation, fp-ts type classes like Eq, Ord, Semigroup, and Monoid provide utilities to implement flexible composition. They define equality, ordering, and combination rules for safe data structure handling.

Can I use pattern matching with discriminated unions and fp-ts?

Yes, you can pattern-match data structures built with fp-ts. Sum types, or discriminated unions, model mutually exclusive states and workflows, and pattern matching safely handles these exclusive states.

Do I need the fp-ts library to implement type classes and ADTs?

Yes, the fp-ts library is required. It provides the necessary Eq, Ord, Semigroup, and Monoid utilities to implement, compose, and pattern-match algebraic data types and type-class instances in TypeScript.

When should I not use algebraic data types for API design?

Avoid algebraic data types for API design when your domain lacks mutually exclusive states or required data compositions. ADTs are best suited for complex domain modeling and validation requiring safe composition.