replace redundant liftM7 function with applicatives

This commit is contained in:
Sergey Vinokurov 2015-05-17 23:22:56 +03:00
parent ac31e6edc2
commit 84134e1fee
2 changed files with 17 additions and 21 deletions

View File

@ -38,7 +38,7 @@ import Paths_ghc_mod as GhcMod
-- | Only package related GHC options, sufficient for things that don't need to
-- access home modules
getGhcPkgOptions :: (MonadIO m, GmEnv m, GmLog m)
getGhcPkgOptions :: (Applicative m, MonadIO m, GmEnv m, GmLog m)
=> m [(ChComponentName, [GHCOption])]
getGhcPkgOptions = map (\c -> (gmcName c, gmcGhcPkgOpts c)) `liftM` getComponents
@ -54,7 +54,7 @@ helperProgs opts = Programs {
--
-- The Component\'s 'gmcHomeModuleGraph' will be empty and has to be resolved by
-- 'resolveGmComponents'.
getComponents :: (MonadIO m, GmEnv m, GmLog m)
getComponents :: (Applicative m, MonadIO m, GmEnv m, GmLog m)
=> m [GmComponent GMCRaw ChEntrypoint]
getComponents = do
opt <- options
@ -67,35 +67,31 @@ getComponents = do
)
withCabal $ cached cradleRootDir cabalHelperCache d
cabalHelperCache :: MonadIO m => Cached m
(Programs, FilePath, (Version, String))
[GmComponent GMCRaw ChEntrypoint]
cabalHelperCache
:: (Functor m, Applicative m, MonadIO m)
=> Cached m (Programs, FilePath, (Version, String)) [GmComponent GMCRaw ChEntrypoint]
cabalHelperCache = Cached {
cacheFile = cabalHelperCacheFile,
cachedAction = \ _ (progs, root, _) _ ->
runQuery' progs root $ do
q <- liftM7 join7
ghcOptions
ghcPkgOptions
ghcSrcOptions
ghcLangOptions
entrypoints
entrypoints
sourceDirs
q <- join7
<$> ghcOptions
<*> ghcPkgOptions
<*> ghcSrcOptions
<*> ghcLangOptions
<*> entrypoints
<*> entrypoints
<*> sourceDirs
let cs = flip map q $ curry8 (GmComponent mempty)
return ([setupConfigPath], cs)
}
where
curry8 fn (a, (b, (c, (d, (e, (f, (g, h))))))) = fn a b c d e f g h
liftM7 fn ma mb mc md me mf mg = do
a <- ma; b <- mb; c <- mc; d <- md; e <- me; f <- mf; g <- mg
return (fn a b c d e f g)
join7 a b c d e f = join' a . join' b . join' c . join' d . join' e . join' f
join' :: Eq a => [(a,b)] -> [(a,c)] -> [(a,(b,c))]
join' lb lc = [ (a, (b, c))
| (a, b) <- lb
| (a, b) <- lb
, (a', c) <- lc
, a == a'
]

View File

@ -18,7 +18,7 @@
module Language.Haskell.GhcMod.Target where
import Control.Arrow
import Control.Applicative ((<$>))
import Control.Applicative (Applicative, (<$>))
import Control.Monad.Reader (runReaderT)
import GHC
import GHC.Paths (libdir)
@ -257,11 +257,11 @@ findCandidates scns = foldl1 Set.intersection scns
pickComponent :: Set ChComponentName -> ChComponentName
pickComponent scn = Set.findMin scn
packageGhcOptions :: (MonadIO m, GmEnv m, GmLog m) => m [GHCOption]
packageGhcOptions :: (Applicative m, MonadIO m, GmEnv m, GmLog m) => m [GHCOption]
packageGhcOptions = do
crdl <- cradle
case cradleCabalFile crdl of
Just _ -> do
Just _ ->
(Set.toList . Set.fromList . concat . map snd) `liftM` getGhcPkgOptions
Nothing -> sandboxOpts crdl