feat: lambda expressions are mutable now
This commit is contained in:
@@ -10,25 +10,25 @@ import "git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
func ReduceOnce(e lambda.Expression) (lambda.Expression, bool) {
|
||||
switch e := e.(type) {
|
||||
case lambda.Abstraction:
|
||||
body, reduced := ReduceOnce(e.Body())
|
||||
body, reduced := ReduceOnce(e.Body)
|
||||
if reduced {
|
||||
return lambda.NewAbstraction(e.Parameter(), body), true
|
||||
return lambda.Abstraction{Parameter: e.Parameter, Body: body}, true
|
||||
}
|
||||
return e, false
|
||||
|
||||
case lambda.Application:
|
||||
if fn, fnOk := e.Abstraction().(lambda.Abstraction); fnOk {
|
||||
return fn.Body().Substitute(fn.Parameter(), e.Argument()), true
|
||||
if fn, fnOk := e.Abstraction.(lambda.Abstraction); fnOk {
|
||||
return fn.Body.Substitute(fn.Parameter, e.Argument), true
|
||||
}
|
||||
|
||||
abs, reduced := ReduceOnce(e.Abstraction())
|
||||
abs, reduced := ReduceOnce(e.Abstraction)
|
||||
if reduced {
|
||||
return lambda.NewApplication(abs, e.Argument()), true
|
||||
return lambda.Application{Abstraction: abs, Argument: e.Argument}, true
|
||||
}
|
||||
|
||||
arg, reduced := ReduceOnce(e.Argument())
|
||||
arg, reduced := ReduceOnce(e.Argument)
|
||||
if reduced {
|
||||
return lambda.NewApplication(e.Abstraction(), arg), true
|
||||
return lambda.Application{Abstraction: e.Abstraction, Argument: arg}, true
|
||||
}
|
||||
|
||||
return e, false
|
||||
|
||||
Reference in New Issue
Block a user