24 lines
446 B
Go
24 lines
446 B
Go
package lambda
|
|
|
|
func ReduceOnce(e *Expression) bool {
|
|
switch typed := (*e).(type) {
|
|
case *Abstraction:
|
|
return ReduceOnce(&typed.Body)
|
|
case *Application:
|
|
fn, fnOk := typed.Abstraction.(*Abstraction)
|
|
if fnOk {
|
|
Substitute(&fn.Body, fn.Parameter, typed.Argument)
|
|
*e = fn.Body
|
|
return true
|
|
}
|
|
good := ReduceOnce(&typed.Abstraction)
|
|
if good {
|
|
return true
|
|
}
|
|
|
|
return ReduceOnce(&typed.Argument)
|
|
default:
|
|
return false
|
|
}
|
|
}
|