liveBook · Manning

Impure layer

As explained in Functional Design and Architecture: Examples in Haskell

An impure layer is an architectural layer that performs side-effecting actions and interacts with the external world.

An impure layer is the application’s boundary with the external world. It performs side-effecting actions, connects application parts, and evaluates behavior declared in a pure layer. Keep it as small as possible so business logic remains easier to reason about. section 2.2.1

A useful architecture separates behavioral declarations from their execution. Business logic can describe scenarios using subsystem interfaces or DSLs, then translate those scenarios into impure code that operates over the interoperability layer. section 2.2.1 section 7.1.2

The separation gives each layer a clearer responsibility:

  • The pure layer contains deterministic behavior and declares actions without evaluating them in an impure environment. section 2.2.1
  • The impure layer may access the outer world and interpret the values or scripts produced by the pure layer. section 2.2.1
  • State is allowed in both layers when represented purely, but impure state is restricted to the impure layer. section 7.1.2

Logging a sandwich recipe

A sandwich recipe can remain a declarative script while adding a logging instruction. The impure interpreter then performs the logging, reads and updates ingredient state, and handles missing ingredients by logging an error and failing. This keeps the recipe’s business sequence distinct from its operational effects. section 7.1.2

Figure 2.13 Layers: descriptions and responsibilities

Use the layer diagram to compare the responsibilities of pure, impure, business-logic, interoperability, and interface layers. section 2.2.1

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines responsibilities, state restrictions, and interpretation, then demonstrates logging, mutable state, and failure handling.
Examples
Uses sandwich construction, logging instructions, ingredient references, mutable updates, and success or failure paths.
What it assumes
Assumes familiarity with application layers, pure functions, business logic, interfaces, and DSL-based behavior.
What you can do after
Designs smaller effect boundaries and interprets pure scripts without mixing operational details into business behavior.
How it connects
Connects pure layers, business logic, interoperability layers, embedded DSLs, interpreters, and application state.

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.