feat: reducer works
This commit is contained in:
@@ -2,6 +2,7 @@ package lambda
|
||||
|
||||
type Expression interface {
|
||||
Accept(Visitor)
|
||||
Copy() Expression
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
@@ -11,14 +12,18 @@ type Abstraction struct {
|
||||
Body Expression
|
||||
}
|
||||
|
||||
func NewAbstraction(parameter string, body Expression) *Abstraction {
|
||||
return &Abstraction{Parameter: parameter, Body: body}
|
||||
func (this *Abstraction) Copy() Expression {
|
||||
return NewAbstraction(this.Parameter, this.Body.Copy())
|
||||
}
|
||||
|
||||
func (this *Abstraction) Accept(v Visitor) {
|
||||
v.VisitAbstraction(this)
|
||||
}
|
||||
|
||||
func NewAbstraction(parameter string, body Expression) *Abstraction {
|
||||
return &Abstraction{Parameter: parameter, Body: body}
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Application struct {
|
||||
@@ -26,28 +31,36 @@ type Application struct {
|
||||
Argument Expression
|
||||
}
|
||||
|
||||
func NewApplication(function Expression, argument Expression) *Application {
|
||||
return &Application{Abstraction: function, Argument: argument}
|
||||
func (this *Application) Copy() Expression {
|
||||
return NewApplication(this.Abstraction.Copy(), this.Argument.Copy())
|
||||
}
|
||||
|
||||
func (this *Application) Accept(v Visitor) {
|
||||
v.VisitApplication(this)
|
||||
}
|
||||
|
||||
func NewApplication(function Expression, argument Expression) *Application {
|
||||
return &Application{Abstraction: function, Argument: argument}
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Variable struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func NewVariable(name string) *Variable {
|
||||
return &Variable{Value: name}
|
||||
func (this *Variable) Copy() Expression {
|
||||
return NewVariable(this.Value)
|
||||
}
|
||||
|
||||
func (this *Variable) Accept(v Visitor) {
|
||||
v.VisitVariable(this)
|
||||
}
|
||||
|
||||
func NewVariable(name string) *Variable {
|
||||
return &Variable{Value: name}
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Visitor interface {
|
||||
|
||||
Reference in New Issue
Block a user