nix-playgraound/notes/039-haskell-map-set-modeling.md

62 lines
1.5 KiB
Markdown
Raw Normal View History

# Haskell Map and Set Modeling
This note covers `36-haskell-map-set-modeling/`, which models release approval policy directly with `Map` and `Set`.
---
## 1. Why These Structures Deserve Their Own Example
Several earlier examples already use `containers`, but only as support code.
This example makes the data structures themselves the teaching point:
- `Map` for service ownership and environment access rules, and
- `Set` for required, supplied, missing, and unexpected approver groups.
That is a practical step up from list-based toy models.
---
## 2. What the Policy Computation Shows
The report logic uses set operations directly:
- intersection for required approvers that are valid in the environment,
- difference for missing approvers, and
- difference again for unexpected approvers.
That makes the policy behavior compact and declarative. The code describes the relationships instead of manually looping over lists.
---
## 3. Why This Is Good Domain Modeling
Ownership, access grants, and approval groups are not “just lists”.
They have semantics:
- service names map to owner teams,
- environments map to allowed teams, and
- approver groups should not contain duplicates.
Using `Map` and `Set` makes those semantics explicit in the type choices.
---
## 4. Commands to Try
```bash
cd 36-haskell-map-set-modeling
nix develop
cabal run
cabal run -- api:production:platform,security
cabal test
nix build
./result/bin/mini-access-policy api:production:platform,security
nix run . -- api:production:platform,security
nix flake check
```