diff options
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 |