Skip to content

Commit 04577e8

Browse files
committed
Simplify the interaction between classification and execution
1 parent 8873fe2 commit 04577e8

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/Main.hs

+4-12
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ main = do
2121
mode <- getMode
2222
if modeTest mode then test else do
2323
settings <- readSettings $ modeHints mode
24-
let ignore idea = let f = classify settings in f idea == Skip
25-
let hints = readHints settings
26-
27-
ideas <- liftM concat $ mapM (runFile ignore hints) (modeFiles mode)
24+
let apply = map (classify settings) . applyHint (readHints settings)
25+
ideas <- liftM concat $ mapM (liftM apply . parseFile) (modeFiles mode)
26+
mapM_ print ideas
27+
2828
let n = length ideas
2929
if n == 0 then do
3030
when (not $ null $ modeReports mode) $ putStrLn "Skipping writing reports"
@@ -34,11 +34,3 @@ main = do
3434
putStrLn $ "Writing report to " ++ x ++ " ..."
3535
writeReport x ideas
3636
putStrLn $ "Found " ++ show n ++ " suggestions"
37-
38-
39-
runFile :: (Idea -> Bool) -> Hint -> FilePath -> IO [Idea]
40-
runFile ignore hint file = do
41-
src <- parseFile file
42-
let ideas = filter (not . ignore) $ applyHint hint src
43-
mapM_ print ideas
44-
return ideas

src/Settings.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pickFiles = mapM parseFile
3030

3131

3232
-- Eta bound variable lifted so the filter only happens once per classify
33-
classify :: [Setting] -> Idea -> Rank
34-
classify xs = \i -> foldl'
33+
classify :: [Setting] -> Idea -> Idea
34+
classify xs = \i -> i{rank=foldl'
3535
(\r c -> if matchHint (hint c) (hint i) && matchFunc (func c) (func i) then rank c else r)
36-
Warn xs2
36+
(rank i) xs2}
3737
where
3838
xs2 = filter isClassify xs
3939

0 commit comments

Comments
 (0)