liveBook · Manning

Applicative style

As explained in Functional Design and Architecture: Examples in Haskell

Applicative validation is a validation technique that combines independent checks while accumulating their errors rather than stopping at the first failure.

Applicative validation checks incoming API data before business logic uses it, transforming externally supplied values into properly justified domain values. Unlike a fail-fast handler, it can express independent checks as a calculation and accumulate their errors. section 14.2.4

The technique emphasizes:

  • Separating the API model from the domain model. section 14.2.4
  • Replacing nested or immediate failure checks with validation combinators. section 14.2.4
  • Reporting multiple independent problems together instead of returning only the first error. section 14.2.4

Pointed nested validation

A validator checks an outer string and a nested integer with <$> and <*>, requiring the integer to be between 0 and 100. Applying it to Outer "" (Inner 0) produces both field-specific errors. section 14.2.4

Figure 14.10 API and domain types

Use the API-to-domain diagram to place validation at the boundary between external request values and justified domain data. section 14.2.4

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines applicative validation and demonstrates combinators, nested validators, and accumulated field errors.
Examples
Uses object-template fields, nested Inner and Outer records, pointed validators, and combined validation errors.
What it assumes
Assumes basic API handlers and data types while contrasting them with validation performed inside business logic.
What you can do after
Apply applicative combinators in Haskell to validate independent fields and report multiple errors.
How it connects
Connects API models, domain models, business logic, Applicative instances, and error accumulation.

Also explained in

Compare how 2 books explain applicative style →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.