perf: implement structural sharing for expression trees #10
@@ -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
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user