refactor: Builder and ConfigBuilder are structurally identical monads — unify via StateT #28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
DSL.Buildercontains two nearly identical monad implementations:Both have hand-written
Functor,Applicative, andMonadinstances that are structurally identical. The only difference is the state type (SectionStatevsConfigState).Consequence
Any new combinator (rollback, local scope, inspection) must be written twice. The instances are copy-paste boilerplate that can silently drift if one is modified.
Options
Option A — Use
StateT s (Either DomainError)Eliminates both hand-written monad implementations.
runBuilderbecomesrunStateT. Requirestransformersormtldependency.Option B — Single polymorphic newtype
Derive all instances once.
Builder scopeandConfigBuilderbecome type aliases. No new dependency.Option C — Keep as-is but add a
HasField-based abstractionLow-risk, no new dependency, but does not remove the duplication.
yorunikakeru referenced this issue2026-06-11 15:42:48 +02:00