diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2019-04-08 22:57:10 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2019-04-08 22:57:10 +0200 |
commit | 8f742dc39085ebd15848ab32662239e8562a430c (patch) | |
tree | b71283d400713d7d96095b715c8ea608c9d84c9a /src/Haskell | |
parent | 57ac7ed93d048397b36e53d50db6d328e31bd2cc (diff) |
Add rewall command
Diffstat (limited to 'src/Haskell')
-rw-r--r-- | src/Haskell/AST.hs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/Haskell/AST.hs b/src/Haskell/AST.hs index 1e181e2..f8b5c72 100644 --- a/src/Haskell/AST.hs +++ b/src/Haskell/AST.hs @@ -105,7 +105,29 @@ instance Pretty Inst where pretty (Inst n t ds) = Node ("instance " ++ n ++ " " ++ pprintOneline t ++ " where") [Bracket "{" "}" ";" (map pretty ds)] -mapInit :: (a -> a) -> [a] -> [a] -mapInit _ [] = [] -mapInit _ [x] = [x] -mapInit f (x:y:zs) = f x : mapInit f (y:zs) +class AllRefs a where + allRefs :: a -> [Name] + +instance AllRefs AST where + allRefs (AST tops) = nub $ concatMap allRefs tops + +instance AllRefs Toplevel where + allRefs (TopDef def) = allRefs def + allRefs (TopDecl _) = [] + allRefs (TopData _) = [] + allRefs (TopClass _) = [] + allRefs (TopInst inst) = allRefs inst + +instance AllRefs Def where + allRefs (Def _ e) = allRefs e + +instance AllRefs Expr where + allRefs (App e es) = nub $ concatMap allRefs (e : es) + allRefs (Ref n) = [n] + allRefs (Num _) = [] + allRefs (Tup es) = nub $ concatMap allRefs es + allRefs (Lam ns e) = allRefs e \\ ns + allRefs (Case e pairs) = nub $ allRefs e ++ concatMap (allRefs . snd) pairs + +instance AllRefs Inst where + allRefs (Inst _ _ ds) = nub $ concatMap allRefs ds |