Files
lambda/pkg/lambda/reduce.go
2025-12-25 00:40:34 -05:00

24 lines
448 B
Go

package lambda
func ReduceOnce(e *Expression) bool {
switch typed := (*e).(type) {
case *Abstraction:
return ReduceOnce(&typed.Body)
case *Application:
fn, fn_ok := typed.Abstraction.(*Abstraction)
if fn_ok {
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
}
}