Implement freeVars

This commit is contained in:
Manuel Thalmann 2024-06-17 00:36:43 +02:00
parent 601ef93a70
commit 922266f917

View file

@ -1,4 +1,4 @@
import Data.Set (Set)
import Data.Set (Set, empty, delete, union, singleton)
--------------------
-- Slides
--------------------
@ -21,6 +21,17 @@ pretty x = case x of
-- >>> pretty (Abs "x" $ Abs "y" $ Inv (Inv Add (Var "x")) (Var "y"))
-- "Lx.Ly.((Add x) y)"
freeVars :: Term -> Set String
freeVars x = case x of
(Abs param term) -> delete param (freeVars term)
(Inv func param) -> freeVars func `union` freeVars param
(Var name) -> singleton name
_ -> empty
-- example
-- >>> freeVars (Inv (Var "y") $ Abs "x" Add)
-- fromList ["y"]
--------------------
-- Exercise 1
--------------------