feat: reducer, but doesn`t work
This commit is contained in:
@@ -1,65 +1,57 @@
|
||||
package lambda
|
||||
|
||||
type Expression interface {
|
||||
Accept(ExpressionVisitor)
|
||||
Accept(Visitor)
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Function struct {
|
||||
type Abstraction struct {
|
||||
Parameter string
|
||||
Body Expression
|
||||
}
|
||||
|
||||
func NewFunction(parameter string, body Expression) *Function {
|
||||
return &Function{
|
||||
Parameter: parameter,
|
||||
Body: body,
|
||||
}
|
||||
func NewAbstraction(parameter string, body Expression) *Abstraction {
|
||||
return &Abstraction{Parameter: parameter, Body: body}
|
||||
}
|
||||
|
||||
func (f *Function) Accept(v ExpressionVisitor) {
|
||||
v.VisitFunction(f)
|
||||
func (this *Abstraction) Accept(v Visitor) {
|
||||
v.VisitAbstraction(this)
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Call struct {
|
||||
Function Expression
|
||||
Argument Expression
|
||||
type Application struct {
|
||||
Abstraction Expression
|
||||
Argument Expression
|
||||
}
|
||||
|
||||
func NewCall(function Expression, argument Expression) *Call {
|
||||
return &Call{
|
||||
Function: function,
|
||||
Argument: argument,
|
||||
}
|
||||
func NewApplication(function Expression, argument Expression) *Application {
|
||||
return &Application{Abstraction: function, Argument: argument}
|
||||
}
|
||||
|
||||
func (c *Call) Accept(v ExpressionVisitor) {
|
||||
v.VisitCall(c)
|
||||
func (this *Application) Accept(v Visitor) {
|
||||
v.VisitApplication(this)
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type Atom struct {
|
||||
type Variable struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func NewAtom(name string) *Atom {
|
||||
return &Atom{
|
||||
Value: name,
|
||||
}
|
||||
func NewVariable(name string) *Variable {
|
||||
return &Variable{Value: name}
|
||||
}
|
||||
|
||||
func (a *Atom) Accept(v ExpressionVisitor) {
|
||||
v.VisitAtom(a)
|
||||
func (this *Variable) Accept(v Visitor) {
|
||||
v.VisitVariable(this)
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type ExpressionVisitor interface {
|
||||
VisitFunction(*Function)
|
||||
VisitCall(*Call)
|
||||
VisitAtom(*Atom)
|
||||
type Visitor interface {
|
||||
VisitAbstraction(*Abstraction)
|
||||
VisitApplication(*Application)
|
||||
VisitVariable(*Variable)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user