1 module Main (main) where
2 import Language.Haskell.Syntax
3 import Language.Haskell.Pretty
4 import Language.Haskell.Parser
9 let filename = "adder.hs"
11 file <- readFile filename
13 let mode = ParseMode {parseFilename = filename}
14 ParseOk mod = parseModuleWithMode mode file
16 --putStr $ foldl (\s d -> s ++ (show d) ++ "\n\n") "" (decls mod)
17 putList (findfunc "exp_adder" (decls mod))
19 decls (HsModule _ _ _ _ decls) =
22 name (HsModule _ n _ _ _) =
26 String -- Function name to find
27 -> [HsDecl] -- Decls to search
30 findfunc name decls = foldl (findmatches name) [] decls
32 -- Look at a HsDecl and add all HsMatches in it with the sought name to res
33 findmatches name res (HsFunBind matches) = res ++ filter (filtermatch name) matches
34 findmatches name res _ = res
36 -- Look at a single match and see if it has the sought name
37 filtermatch name (HsMatch _ (HsIdent n) _ _ _) =
40 -- Print a list of showable things, separated by newlines instead of ,
41 -- Also pretty prints them
42 putList :: (Show a, Pretty a) => [a] -> IO ()
47 putStr $ prettyPrint x
54 -- Add indentations to the given string
55 indent :: Int -> String -> IO ()
61 putStr (replicate (n + 1) ' ')
66 putStr (replicate (n - 1) ' ')
73 indent n [] = do return ()