feat: reducer, but doesn`t work
This commit is contained in:
20
pkg/lambda/get_free_variables.go
Normal file
20
pkg/lambda/get_free_variables.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package lambda
|
||||
|
||||
import "git.maximhutz.com/max/lambda/pkg/set"
|
||||
|
||||
func GetFreeVariables(e Expression) set.Set[string] {
|
||||
switch e := e.(type) {
|
||||
case *Variable:
|
||||
return set.New(e.Value)
|
||||
case *Abstraction:
|
||||
vars := GetFreeVariables(e.Body)
|
||||
vars.Remove(e.Parameter)
|
||||
return vars
|
||||
case *Application:
|
||||
vars := GetFreeVariables(e.Abstraction)
|
||||
vars.Union(GetFreeVariables(e.Argument))
|
||||
return vars
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user