liveBook · Manning

Fine-grained data model

As explained in Functional Design and Architecture: Examples in Haskell

A fine-grained data model organizes mutable data into independently updateable smaller units.

A fine-grained data model organizes mutable state into independently updateable units. In a concurrent simulation, changing one value does not require replacing the surrounding structure, allowing control to be distributed across threads. section 8.2.2

Contrast the two update strategies:

  • A coarse-grained map stores the whole map in one MVar; changing a value requires constructing and storing a new map. section 8.2.2
  • A fine-grained structure stores a map of keys to individual MVars, so an update can alter the inner value without changing the outer map. section 8.2.2
  • The distinction matters especially for STM-based concurrent models, where repeated updates to the same key can otherwise cause repeated outer-state updates. section 8.2.2
Figure 8.8 Data structure with two layers of concurrent mutability

Use the diagram to inspect the two layers of concurrent mutability represented by the outer map and inner values. section 8.2.2

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains nested mutable structure and update costs, while deferring broader coarse-grained versus fine-grained STM treatment.
Examples
Uses a CoarseGrainedMap and a nested MVar map to compare whole-structure replacement with localized mutation.
What you can do after
Evaluate whether mutable concurrent state should update individual values or replace an enclosing structure.
How it connects
Connects mutable data design with concurrency, STM, MVar, and coarse-grained data models.

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.