Implement freeVars
This commit is contained in:
parent
601ef93a70
commit
922266f917
1 changed files with 12 additions and 1 deletions
|
@ -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
|
||||
--------------------
|
||||
|
|
Loading…
Reference in a new issue