nix-playgraound/notes/046-haskell-tree-rollouts.md

1.4 KiB

Haskell Tree Rollouts

This note covers 43-haskell-tree-rollouts/, which uses Data.Tree to model a rollout plan as a real hierarchy instead of as a flat list.


1. Why a Tree Fits This Domain

Some rollout structures are naturally nested:

  • one release at the root,
  • one environment branch under that release, and
  • one or more service leaves under each environment.

That is exactly what Tree a expresses. Each node has one value plus zero or more child nodes.


2. What the Example Computes from the Tree

The example does two different things with the same samplePlan:

  • renderPlan turns the hierarchy into an indented ASCII tree, and
  • deploymentPaths turns each root-to-leaf path into an ordered rollout path.

That contrast is the main teaching point. One tree can support both human-readable structure and programmatic traversal.


3. Why the Test Checks Paths, Not Just Pretty Output

The important behavior is not the ASCII drawing by itself. It is the fact that the traversal preserves parent context.

That is why the test checks strings such as:

  • checkout-release -> staging -> api, and
  • checkout-release -> production -> billing.

Those paths prove the example is walking the tree shape correctly.


4. Commands to Try

cd 43-haskell-tree-rollouts

nix develop
cabal run
cabal test

nix build
./result/bin/mini-tree-rollouts

nix run
nix flake check