refactor: remove visitor pattern #37

Merged
mvhutz merged 2 commits from refactor/no-visitor-pattern into main 2026-01-17 20:46:07 +00:00
Owner

Description

The codebase previously used the visitor pattern for traversing lambda calculus expressions.
This was a hold-over from avoiding the Go-idiomatic way of handling types.
This PR removes the visitor pattern in favor of direct method implementations.

  • Remove Visitor interface from expression.go.
  • Remove Accept methods from Abstraction, Application, and Variable.
  • Remove Accept from Expression interface.
  • Delete stringify.go and move String() logic directly into each type.
  • Add compile-time interface checks (var _ Expression = (*Type)(nil)).
  • Update expr.Expression to embed fmt.Stringer instead of declaring String() string.

Decisions

  • Moved String() implementations directly into each expression type rather than using a separate recursive function, as each type's string representation is simple enough to be self-contained.

Benefits

  • Simpler, more idiomatic Go code using type methods instead of visitor pattern.
  • Reduced indirection and fewer files to maintain.
  • Compile-time interface satisfaction checks catch implementation errors early.

Checklist

  • Code follows conventional commit format.
  • Branch follows naming convention (<type>/<description>).
  • Tests pass (if applicable).
  • Documentation updated (if applicable).

Closes #36

## Description The codebase previously used the visitor pattern for traversing lambda calculus expressions. This was a hold-over from avoiding the Go-idiomatic way of handling types. This PR removes the visitor pattern in favor of direct method implementations. - Remove `Visitor` interface from `expression.go`. - Remove `Accept` methods from `Abstraction`, `Application`, and `Variable`. - Remove `Accept` from `Expression` interface. - Delete `stringify.go` and move `String()` logic directly into each type. - Add compile-time interface checks (`var _ Expression = (*Type)(nil)`). - Update `expr.Expression` to embed `fmt.Stringer` instead of declaring `String() string`. ### Decisions - Moved `String()` implementations directly into each expression type rather than using a separate recursive function, as each type's string representation is simple enough to be self-contained. ## Benefits - Simpler, more idiomatic Go code using type methods instead of visitor pattern. - Reduced indirection and fewer files to maintain. - Compile-time interface satisfaction checks catch implementation errors early. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). - [x] Tests pass (if applicable). - [ ] Documentation updated (if applicable). Closes #36
mvhutz added 2 commits 2026-01-17 20:45:13 +00:00
mvhutz merged commit c2aa77cb92 into main 2026-01-17 20:46:07 +00:00
mvhutz deleted branch refactor/no-visitor-pattern 2026-01-17 20:46:07 +00:00
Sign in to join this conversation.