71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package lambda
|
|
|
|
type Expression interface {
|
|
Accept(Visitor)
|
|
Copy() Expression
|
|
}
|
|
|
|
/** ------------------------------------------------------------------------- */
|
|
|
|
type Abstraction struct {
|
|
Parameter string
|
|
Body Expression
|
|
}
|
|
|
|
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 {
|
|
Abstraction Expression
|
|
Argument Expression
|
|
}
|
|
|
|
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 (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 {
|
|
VisitAbstraction(*Abstraction)
|
|
VisitApplication(*Application)
|
|
VisitVariable(*Variable)
|
|
}
|