perf: implement structural sharing for expression trees #10

Merged
mvhutz merged 5 commits from perf/structural-sharing into main 2026-01-11 02:15:38 +00:00
3 changed files with 0 additions and 6 deletions
Showing only changes of commit ae2ce6fd2f - Show all commits

View File

@@ -1,13 +1,11 @@
package lambda
// Expression represents an immutable lambda calculus expression.
type Expression interface {
Accept(Visitor)
}
/** ------------------------------------------------------------------------- */
// Abstraction represents a lambda abstraction (λx. body).
type Abstraction struct {
parameter string
body Expression
@@ -31,7 +29,6 @@ func NewAbstraction(parameter string, body Expression) *Abstraction {
/** ------------------------------------------------------------------------- */
// Application represents function application (f arg).
type Application struct {
function Expression
argument Expression
@@ -55,7 +52,6 @@ func NewApplication(function Expression, argument Expression) *Application {
/** ------------------------------------------------------------------------- */
// Variable represents a variable reference.
type Variable struct {
value string
}

View File

@@ -1,6 +1,5 @@
package lambda
// Rename replaces all occurrences of target variable with newName.
func Rename(expr Expression, target string, newName string) Expression {
switch e := expr.(type) {
case *Variable:

View File

@@ -1,6 +1,5 @@
package lambda
// Substitute replaces all free occurrences of target with replacement.
func Substitute(expr Expression, target string, replacement Expression) Expression {
switch e := expr.(type) {
case *Variable: