Resource Cleanup Boundary

This triad compares two ways to guarantee resource cleanup while keeping the teaching example small and deterministic.

The example uses a fake audit resource so we can inspect the exact trace for success and failure without depending on a real file handle or database connection.

What It Shows

  • explicit acquire / use / release flow
  • deterministic cleanup on both success and failure
  • pure planning separated from effectful resource handling
  • a direct bridge from C# using and try/finally to Haskell bracket

Modules

  • /Users/scottpeterson/Dev/PurelyFunctional/HaskellDemo/src/Shared/ResourceCleanup.hs
  • /Users/scottpeterson/Dev/PurelyFunctional/HaskellDemo/src/Baseline/ResourceCleanup.hs
  • /Users/scottpeterson/Dev/PurelyFunctional/HaskellDemo/src/HaskellStyle/ResourceCleanup.hs

Baseline Shape

Baseline.ResourceCleanup.runResourceCleanupInline acquires the resource, performs the work, and releases it with manual inline cleanup.

That keeps the lifecycle visible, but acquisition, work, failure handling, and cleanup all stay mixed together.

Haskell-Style Shape

HaskellStyle.ResourceCleanup splits the problem into two layers:

  • planResourceWork is pure and decides which writes and result should happen
  • runResourceCleanupWithBracket uses bracket to guarantee release around the effectful resource scope

That split makes the cleanup boundary reusable without hiding the lifecycle itself.

Why It Fits This Repo

This example extends the same themes already present in the project:

  • effects at the edge
  • explicit workflow orchestration
  • deterministic testing of infrastructure boundaries
  • deeper feature-style comparisons that still stay small enough to read end to end