@@ -0,0 +1,53 @@
1+module LetBoundVars (letBoundVars) where
6+class LetBoundVars a where
7+ letBoundVars :: a -> [String]
9+instance LetBoundVars a => LetBoundVars [a] where
10+ letBoundVars = concatMap letBoundVars
12+instance LetBoundVars Statement where
15+ Definition d -> letBoundVars d
16+ Datatype _ _ tcs -> []
17+ ImportEvent _ e _ _ -> letBoundVars' e
18+ ExportEvent _ _ _ -> []
19+ TypeAnnotation _ _ -> []
20+ TypeAlias _ _ _ -> []
22+instance LetBoundVars Def where
23+ letBoundVars (FnDef n _ e) = n : letBoundVars' e
24+ letBoundVars (OpDef _ _ _ e) = letBoundVars' e
26+letBoundVars' :: CExpr -> [String]
27+letBoundVars' (C _ _ e) = letBoundVars e
29+instance LetBoundVars Expr where
31+ let f = letBoundVars' in
38+ Range e1 e2 -> f e1 ++ f e2
41+ Insert e1 _ e2 -> f e1 ++ f e2
42+ Modify e ps -> f e ++ concatMap (f . snd) ps
43+ Record trps -> concatMap (\(_,_,e) -> f e) trps
44+ Binop op e1 e2 -> f e1 ++ f e2
46+ App e1 e2 -> f e1 ++ f e2
47+ If e1 e2 e3 -> concatMap f [e1,e2,e3]
48+ MultiIf ps -> concatMap (\(b,e) -> f b ++ f e) ps
49+ Let defs e -> concatMap letBoundVars defs ++ f e
51+ Data name es -> concatMap f es
52+ Case e cases -> f e ++ concatMap (f . snd) cases