Commit d74534d0 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Style tweak: s/maybe (return ())/traverse_/.

parent 5413af58
......@@ -107,21 +107,22 @@ module Distribution.PackageDescription (
) where
import Distribution.Compat.Binary (Binary)
import Data.Data (Data)
import Data.List (nub, intercalate)
import Data.Maybe (fromMaybe, maybeToList)
import Data.Data (Data)
import Data.Foldable (traverse_)
import Data.List (nub, intercalate)
import Data.Maybe (fromMaybe, maybeToList)
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid (Monoid(mempty, mappend))
import Data.Monoid (Monoid(mempty, mappend))
#endif
import Data.Typeable ( Typeable )
import Control.Monad (MonadPlus(mplus))
import GHC.Generics (Generic)
import Data.Typeable ( Typeable )
import Control.Monad (MonadPlus(mplus))
import GHC.Generics (Generic)
import Text.PrettyPrint as Disp
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import Distribution.Compat.ReadP ((<++))
import qualified Data.Char as Char (isAlphaNum, isDigit, toLower)
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Map (Map)
import Distribution.Package
( PackageName(PackageName), PackageIdentifier(PackageIdentifier)
......@@ -408,7 +409,7 @@ maybeHasLibs p =
-- function with the library build info as argument.
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib pkg_descr f =
maybe (return ()) f (maybeHasLibs pkg_descr)
traverse_ f (maybeHasLibs pkg_descr)
-- | Get all the module names from the library (exposed and internal modules)
-- which need to be compiled. (This does not include reexports, which
......
......@@ -41,15 +41,16 @@ module Distribution.PackageDescription.Parse (
flagFieldDescrs
) where
import Data.Char (isSpace)
import Data.Maybe (listToMaybe, isJust)
import Data.List (nub, unfoldr, partition, (\\))
import Data.Char (isSpace)
import Data.Foldable (traverse_)
import Data.Maybe (listToMaybe, isJust)
import Data.List (nub, unfoldr, partition, (\\))
import Control.Monad (liftM, foldM, when, unless, ap)
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid ( Monoid(..) )
import Data.Monoid (Monoid(..))
import Control.Applicative (Applicative(..))
#endif
import Control.Arrow (first)
import Control.Arrow (first)
import System.Directory (doesFileExist)
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
import Data.Typeable
......@@ -1094,7 +1095,7 @@ parsePackageDescription file = do
PM ()
checkForUndefinedFlags flags mlib exes tests = do
let definedFlags = map flagName flags
maybe (return ()) (checkCondTreeFlags definedFlags) mlib
traverse_ (checkCondTreeFlags definedFlags) mlib
mapM_ (checkCondTreeFlags definedFlags . snd) exes
mapM_ (checkCondTreeFlags definedFlags . snd) tests
......
......@@ -112,6 +112,7 @@ import Distribution.Compat.Environment (getEnvironment)
import Distribution.Compat.Exception (catchIO)
import Control.Monad (when)
import Data.Foldable (traverse_)
import Data.List (intercalate, unionBy, nub, (\\))
-- | A simple implementation of @main@ for a Cabal setup script.
......@@ -483,7 +484,7 @@ clean pkg_descr flags = do
mapM_ removeFileOrDirectory (extraTmpFiles pkg_descr)
-- If the user wanted to save the config, write it back
maybe (return ()) (writePersistBuildConfig distPref) maybeConfig
traverse_ (writePersistBuildConfig distPref) maybeConfig
where
removeFileOrDirectory :: FilePath -> IO ()
......
......@@ -85,6 +85,7 @@ import Language.Haskell.Extension
import Control.Monad ( when, forM_ )
import Data.Either ( rights )
import Data.Foldable ( traverse_ )
import Data.Monoid
import Data.Maybe ( fromMaybe, listToMaybe )
......@@ -409,7 +410,7 @@ getInterfaces :: Verbosity
-> IO HaddockArgs
getInterfaces verbosity lbi clbi htmlTemplate = do
(packageFlags, warnings) <- haddockPackageFlags lbi clbi htmlTemplate
maybe (return ()) (warn verbosity) warnings
traverse_ (warn verbosity) warnings
return $ mempty {
argInterfaces = packageFlags
}
......
......@@ -133,12 +133,14 @@ import Control.Monad
( join, when, unless, filterM )
import Control.Concurrent.MVar
( newEmptyMVar, putMVar, takeMVar )
import Data.List
( nub, unfoldr, isPrefixOf, tails, intercalate )
import Data.Char as Char
( isDigit, toLower, chr, ord )
import Data.Bits
( Bits((.|.), (.&.), shiftL, shiftR) )
import Data.Char as Char
( isDigit, toLower, chr, ord )
import Data.Foldable
( traverse_ )
import Data.List
( nub, unfoldr, isPrefixOf, tails, intercalate )
import qualified Data.ByteString.Lazy as BS
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
import qualified Data.Set as Set
......@@ -356,7 +358,7 @@ printRawCommandAndArgsAndEnv :: Verbosity
-> IO ()
printRawCommandAndArgsAndEnv verbosity path args menv
| verbosity >= deafening = do
maybe (return ()) (putStrLn . ("Environment: " ++) . show) menv
traverse_ (putStrLn . ("Environment: " ++) . show) menv
print (path, args)
| verbosity >= verbose = putStrLn $ showCommandForUser path args
| otherwise = return ()
......
......@@ -29,6 +29,8 @@ module Distribution.Client.Install (
pruneInstallPlan
) where
import Data.Foldable
( traverse_ )
import Data.List
( isPrefixOf, unfoldr, nub, sort, (\\) )
import qualified Data.Set as S
......@@ -48,6 +50,8 @@ import Distribution.Compat.Exception
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative
( (<$>) )
import Data.Traversable
( traverse )
#endif
import Control.Monad
( forM_, when, unless )
......@@ -1476,9 +1480,8 @@ installUnpackedPackage verbosity buildLimit installLock numJobs pkg_key
setup cmd flags mLogPath =
Exception.bracket
(maybe (return Nothing)
(\path -> Just `fmap` openFile path AppendMode) mLogPath)
(maybe (return ()) hClose)
(traverse (\path -> openFile path AppendMode) mLogPath)
(traverse_ hClose)
(\logFileHandle ->
setupWrapper verbosity
scriptOptions { useLoggingHandle = logFileHandle
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment