liveBook · Manning

Pure layer

As explained in Functional Design and Architecture: Examples in Haskell

A pure layer is an architectural layer containing deterministic code that describes behavior without performing impure evaluation.

A pure layer contains deterministic code that declares behavior without evaluating it in an impure environment. Its services use functional interfaces and declarative data-storage descriptions; real storage and other effects belong elsewhere. section 2.2.1

Use the boundary to keep architectural responsibilities visible:

  • Keep domain models, data types, DSLs, and domain logic pure; impure cases are treated as harmful. section 2.2.1
  • Let business-logic scenarios describe application behavior and translate them into impure code only when they must operate through the interoperability layer. section 2.2.1
  • Place evaluation, outer-world access, and impure actions in the impure layer, which interprets logic declared by the pure layer. section 2.2.1
  • Treat pure state as allowed in the pure layer, while impure state remains disallowed there and permitted in the impure layer. section 7.1.2

A sandwich recipe with logging

A sandwich recipe can remain a declarative script: start the sandwich, add cheese and salt, finish it, and request an informational log. The pure script describes these operations; an impure interpreter reads and updates ingredient state, emits logs, and handles missing ingredients. section 7.1.2

Figure 2.13 Layers: descriptions and responsibilities

Use the layer diagram to trace how pure descriptions, business logic, interoperability, presentation, and impure evaluation divide responsibilities. section 2.2.1

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines the boundary, assigns state permissions, and illustrates logging and interpretation, without detailing a complete implementation.
Examples
Uses sandwich construction, free scripts, logging requests, ingredient state, and an impure interpreter.
What you can do after
Evaluate/understand how to organize declarative logic and defer effects to an interpreter or impure layer.
How it connects
Connects domain model, business logic, interoperability, impure layer, state, DSLs, and interpreters.

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.