diff --git a/Cabal/Distribution/Backpack/LinkedComponent.hs b/Cabal/Distribution/Backpack/LinkedComponent.hs index 584fc5d713f..569d70a7689 100644 --- a/Cabal/Distribution/Backpack/LinkedComponent.hs +++ b/Cabal/Distribution/Backpack/LinkedComponent.hs @@ -43,11 +43,8 @@ import Distribution.Utils.LogProgress import qualified Data.Set as Set import qualified Data.Map as Map -import Data.Traversable - ( mapM ) import Distribution.Pretty (pretty) -import Text.PrettyPrint -import Data.Either +import Text.PrettyPrint (Doc, hang, text, vcat, ($+$), hsep, quotes) -- | A linked component is a component that has been mix-in linked, at -- which point we have determined how all the dependencies of the @@ -187,19 +184,19 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent { m_u <- convertModule (OpenModule this_uid m) return (Map.singleton m [WithSource (from m) m_u], Map.empty) -- Handle 'exposed-modules' - exposed_mod_shapes_u <- mapM (convertMod FromExposedModules) src_provs + exposed_mod_shapes_u <- traverse (convertMod FromExposedModules) src_provs -- Handle 'other-modules' - other_mod_shapes_u <- mapM (convertMod FromOtherModules) src_hidden + other_mod_shapes_u <- traverse (convertMod FromOtherModules) src_hidden -- Handle 'signatures' let convertReq :: ModuleName -> UnifyM s (ModuleScopeU s) convertReq req = do req_u <- convertModule (OpenModuleVar req) return (Map.empty, Map.singleton req [WithSource (FromSignatures req) req_u]) - req_shapes_u <- mapM convertReq src_reqs + req_shapes_u <- traverse convertReq src_reqs -- Handle 'mixins' - (incl_shapes_u, all_includes_u) <- fmap unzip (mapM convertInclude unlinked_includes) + (incl_shapes_u, all_includes_u) <- fmap unzip (traverse convertInclude unlinked_includes) failIfErrs -- Prevent error cascade -- Mix-in link everything! mixLink is the real workhorse. @@ -208,7 +205,7 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent { ++ req_shapes_u ++ incl_shapes_u - -- src_reqs_u <- mapM convertReq src_reqs + -- src_reqs_u <- traverse convertReq src_reqs -- Read out all the final results by converting back -- into a pure representation. let convertIncludeU (ComponentInclude dep_aid rns i) = do @@ -220,8 +217,8 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent { }) shape <- convertModuleScopeU shape_u let (includes_u, sig_includes_u) = partitionEithers all_includes_u - incls <- mapM convertIncludeU includes_u - sig_incls <- mapM convertIncludeU sig_includes_u + incls <- traverse convertIncludeU includes_u + sig_incls <- traverse convertIncludeU sig_includes_u return (shape, incls, sig_incls) let isNotLib (CLib _) = False diff --git a/Cabal/Distribution/Backpack/ReadyComponent.hs b/Cabal/Distribution/Backpack/ReadyComponent.hs index 950a6434bf0..1064776203b 100644 --- a/Cabal/Distribution/Backpack/ReadyComponent.hs +++ b/Cabal/Distribution/Backpack/ReadyComponent.hs @@ -39,9 +39,6 @@ import Distribution.ModuleName import Distribution.Package import Distribution.Simple.Utils -import qualified Control.Applicative as A -import qualified Data.Traversable as T - import Control.Monad import Text.PrettyPrint import qualified Data.Map as Map @@ -198,14 +195,14 @@ instance Functor InstM where fmap f (InstM m) = InstM $ \s -> let (x, s') = m s in (f x, s') -instance A.Applicative InstM where +instance Applicative InstM where pure a = InstM $ \s -> (a, s) InstM f <*> InstM x = InstM $ \s -> let (f', s') = f s (x', s'') = x s' in (f' x', s'') instance Monad InstM where - return = A.pure + return = pure InstM m >>= f = InstM $ \s -> let (x, s') = m s in runInstM (f x) s' @@ -259,20 +256,20 @@ toReadyComponents pid_map subst0 comps -> InstM (Maybe ReadyComponent) instantiateComponent uid cid insts | Just lc <- Map.lookup cid cmap = do - provides <- T.mapM (substModule insts) (modShapeProvides (lc_shape lc)) + provides <- traverse (substModule insts) (modShapeProvides (lc_shape lc)) -- NB: lc_sig_includes is omitted here, because we don't -- need them to build includes <- forM (lc_includes lc) $ \ci -> do uid' <- substUnitId insts (ci_id ci) return ci { ci_ann_id = fmap (const uid') (ci_ann_id ci) } - exe_deps <- mapM (substExeDep insts) (lc_exe_deps lc) + exe_deps <- traverse (substExeDep insts) (lc_exe_deps lc) s <- InstM $ \s -> (s, s) let getDep (Module dep_def_uid _) | let dep_uid = unDefUnitId dep_def_uid -- Lose DefUnitId invariant for rc_depends = [(dep_uid, fromMaybe err_pid $ - Map.lookup dep_uid pid_map A.<|> + Map.lookup dep_uid pid_map <|> fmap rc_munged_id (join (Map.lookup dep_uid s)))] where err_pid = MungedPackageId @@ -313,7 +310,7 @@ toReadyComponents pid_map subst0 comps substSubst :: Map ModuleName Module -> Map ModuleName OpenModule -> InstM (Map ModuleName Module) - substSubst subst insts = T.mapM (substModule subst) insts + substSubst subst insts = traverse (substModule subst) insts substModule :: Map ModuleName Module -> OpenModule -> InstM Module substModule subst (OpenModuleVar mod_name) @@ -346,7 +343,7 @@ toReadyComponents pid_map subst0 comps then do uid' <- substUnitId Map.empty (ci_id ci) return $ ci { ci_ann_id = fmap (const (DefiniteUnitId uid')) (ci_ann_id ci) } else return ci - exe_deps <- mapM (substExeDep Map.empty) (lc_exe_deps lc) + exe_deps <- traverse (substExeDep Map.empty) (lc_exe_deps lc) let indefc = IndefiniteComponent { indefc_requires = map fst (lc_insts lc), indefc_provides = modShapeProvides (lc_shape lc), diff --git a/Cabal/Distribution/Backpack/UnifyM.hs b/Cabal/Distribution/Backpack/UnifyM.hs index 2d2e55909a9..18a3e3702ab 100644 --- a/Cabal/Distribution/Backpack/UnifyM.hs +++ b/Cabal/Distribution/Backpack/UnifyM.hs @@ -70,7 +70,6 @@ import qualified Data.Map as Map import qualified Data.Set as Set import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap -import qualified Data.Traversable as T import Text.PrettyPrint -- TODO: more detailed trace output on high verbosity would probably @@ -321,7 +320,7 @@ convertUnitId' _ (DefiniteUnitId uid) = convertUnitId' stk (IndefFullUnitId cid insts) = do fs <- fmap unify_uniq getUnifEnv x <- liftST $ UnionFind.fresh (error "convertUnitId") -- tie the knot later - insts_u <- T.forM insts $ convertModule' (extendMuEnv stk x) + insts_u <- for insts $ convertModule' (extendMuEnv stk x) u <- readUnifRef fs writeUnifRef fs (u+1) y <- liftST $ UnionFind.fresh (UnitIdU u cid insts_u) @@ -359,11 +358,11 @@ type ModuleSubstU s = Map ModuleName (ModuleU s) -- | Conversion of 'ModuleSubst' to 'ModuleSubstU' convertModuleSubst :: Map ModuleName OpenModule -> UnifyM s (Map ModuleName (ModuleU s)) -convertModuleSubst = T.mapM convertModule +convertModuleSubst = traverse convertModule -- | Conversion of 'ModuleSubstU' to 'ModuleSubst' convertModuleSubstU :: ModuleSubstU s -> UnifyM s OpenModuleSubst -convertModuleSubstU = T.mapM convertModuleU +convertModuleSubstU = traverse convertModuleU ----------------------------------------------------------------------- -- Conversion from the unifiable data types @@ -400,7 +399,7 @@ convertUnitIdU' stk uid_u = do failWith (text "Unsupported mutually recursive unit identifier") -- return (UnitIdVar i) Nothing -> do - insts <- T.forM insts_u $ convertModuleU' (extendMooEnv stk u) + insts <- for insts_u $ convertModuleU' (extendMooEnv stk u) return (IndefFullUnitId cid insts) convertModuleU' :: MooEnv -> ModuleU s -> UnifyM s OpenModule @@ -615,11 +614,11 @@ convertModuleScopeU (provs_u, reqs_u) = do -- | Convert a 'ModuleProvides' to a 'ModuleProvidesU' convertModuleProvides :: ModuleProvides -> UnifyM s (ModuleProvidesU s) -convertModuleProvides = T.mapM (mapM (T.mapM convertModule)) +convertModuleProvides = traverse (traverse (traverse convertModule)) -- | Convert a 'ModuleProvidesU' to a 'ModuleProvides' convertModuleProvidesU :: ModuleProvidesU s -> UnifyM s ModuleProvides -convertModuleProvidesU = T.mapM (mapM (T.mapM convertModuleU)) +convertModuleProvidesU = traverse (traverse (traverse convertModuleU)) convertModuleRequires :: ModuleRequires -> UnifyM s (ModuleRequiresU s) convertModuleRequires = convertModuleProvides diff --git a/Cabal/Distribution/Compat/CopyFile.hs b/Cabal/Distribution/Compat/CopyFile.hs index 449181c19b9..7a9762f641d 100644 --- a/Cabal/Distribution/Compat/CopyFile.hs +++ b/Cabal/Distribution/Compat/CopyFile.hs @@ -14,13 +14,11 @@ module Distribution.Compat.CopyFile ( import Prelude () import Distribution.Compat.Prelude -import Distribution.Compat.Exception - #ifndef mingw32_HOST_OS import Distribution.Compat.Internal.TempFile import Control.Exception - ( bracketOnError, throwIO ) + ( bracketOnError ) import qualified Data.ByteString.Lazy as BSL import System.IO.Error ( ioeSetLocation ) @@ -43,8 +41,6 @@ import Foreign.C #else /* else mingw32_HOST_OS */ -import Control.Exception - ( throwIO ) import qualified Data.ByteString.Lazy as BSL import System.IO.Error ( ioeSetLocation ) diff --git a/Cabal/Distribution/Compat/Exception.hs b/Cabal/Distribution/Compat/Exception.hs index c7a4ccd6564..b3b0282afd5 100644 --- a/Cabal/Distribution/Compat/Exception.hs +++ b/Cabal/Distribution/Compat/Exception.hs @@ -6,22 +6,32 @@ module Distribution.Compat.Exception ( displayException, ) where +#ifdef MIN_VERSION_base +#define MINVER_base_48 MIN_VERSION_base(4,8,0) +#else +#define MINVER_base_48 (__GLASGOW_HASKELL__ >= 710) +#endif + import System.Exit import qualified Control.Exception as Exception -#if __GLASGOW_HASKELL__ >= 710 + +#if MINVER_base_48 import Control.Exception (displayException) #endif +-- | Try 'IOException'. tryIO :: IO a -> IO (Either Exception.IOException a) tryIO = Exception.try +-- | Catch 'IOException'. catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a catchIO = Exception.catch +-- | Catch 'ExitCode' catchExit :: IO a -> (ExitCode -> IO a) -> IO a catchExit = Exception.catch -#if __GLASGOW_HASKELL__ < 710 +#if !MINVER_base_48 displayException :: Exception.Exception e => e -> String displayException = show #endif diff --git a/Cabal/Distribution/Compat/Graph.hs b/Cabal/Distribution/Compat/Graph.hs index 8b8b7d3e9d1..a326b0c0927 100644 --- a/Cabal/Distribution/Compat/Graph.hs +++ b/Cabal/Distribution/Compat/Graph.hs @@ -88,7 +88,6 @@ import Distribution.Compat.Prelude hiding (empty, lookup, null, toList) import Prelude () import Data.Array ((!)) -import Data.Either (partitionEithers) import Data.Graph (SCC (..)) import Distribution.Utils.Structured (Structure (..), Structured (..)) diff --git a/Cabal/Distribution/Compat/Lens.hs b/Cabal/Distribution/Compat/Lens.hs index 748c23dd172..2ea10e6e0bc 100644 --- a/Cabal/Distribution/Compat/Lens.hs +++ b/Cabal/Distribution/Compat/Lens.hs @@ -50,7 +50,6 @@ module Distribution.Compat.Lens ( import Prelude() import Distribution.Compat.Prelude -import Control.Applicative (Const (..)) import Control.Monad.State.Class (MonadState (..), gets, modify) import qualified Distribution.Compat.DList as DList diff --git a/Cabal/Distribution/Compat/Prelude.hs b/Cabal/Distribution/Compat/Prelude.hs index f1e00ef99c8..b52c93aec63 100644 --- a/Cabal/Distribution/Compat/Prelude.hs +++ b/Cabal/Distribution/Compat/Prelude.hs @@ -1,8 +1,8 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE Trustworthy #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE Trustworthy #-} +{-# LANGUAGE TypeOperators #-} #ifdef MIN_VERSION_base #define MINVER_base_411 MIN_VERSION_base(4,11,0) @@ -50,8 +50,12 @@ module Distribution.Compat.Prelude ( NonEmptySet, Identity (..), Proxy (..), + Const (..), Void, + -- * Data.Either + partitionEithers, + -- * Data.Maybe catMaybes, mapMaybe, fromMaybe, @@ -64,6 +68,7 @@ module Distribution.Compat.Prelude ( intercalate, intersperse, sort, sortBy, nub, nubBy, + partition, -- * Data.List.NonEmpty NonEmpty((:|)), foldl1, foldr1, @@ -81,6 +86,12 @@ module Distribution.Compat.Prelude ( Traversable, traverse, sequenceA, for, + -- * Data.Function + on, + + -- * Data.Ord + comparing, + -- * Control.Arrow first, @@ -89,6 +100,18 @@ module Distribution.Compat.Prelude ( unless, when, ap, void, foldM, filterM, + join, guard, + + -- * Control.Exception + catch, throwIO, evaluate, + Exception (..), IOException, SomeException (..), +#if !MINVER_base_48 + displayException, +#endif + tryIO, catchIO, catchExit, + + -- * Control.DeepSeq + deepseq, force, -- * Data.Char isSpace, isDigit, isUpper, isAlpha, isAlphaNum, @@ -104,75 +127,75 @@ module Distribution.Compat.Prelude ( Int8, Int16, Int32, Int64, -- * Text.PrettyPrint - (<<>>), + (<<>>), (Disp.<+>), + + -- * System.Exit + ExitCode (..), + exitWith, exitSuccess, exitFailure, -- * Text.Read readMaybe, + + -- * Debug.Trace (as deprecated functions) + traceShow, traceShowId, ) where -- We also could hide few partial function -import Prelude as BasePrelude hiding - ( mapM, mapM_, sequence, null, length, foldr, any, all, head, tail, last, init - -- partial functions - , read - , foldr1, foldl1 -#if MINVER_base_411 - -- As of base 4.11.0.0 Prelude exports part of Semigroup(..). - -- Hide this so we instead rely on Distribution.Compat.Semigroup. - , Semigroup(..) -#endif -#if MINVER_base_48 - , Word - -- We hide them, as we import only some members - , Traversable, traverse, sequenceA - , Foldable, foldMap -#endif - ) +import Prelude as BasePrelude hiding + (Foldable, Semigroup (..), Traversable, Word, all, any, foldMap, foldl1, foldr, foldr1, head, init, last, length, mapM, mapM_, null, read, sequence, + sequenceA, tail, traverse) #if !MINVER_base_48 import Control.Applicative (Applicative (..), (<$), (<$>)) -import Distribution.Compat.Semigroup (Monoid (..)) +import Control.Exception (displayException) import Data.Foldable (toList) +import Distribution.Compat.Semigroup (Monoid (..)) #else -import Data.Foldable (length, null, Foldable(toList)) +import Data.Foldable (Foldable (toList), length, null) #endif -import Data.Foldable (Foldable (foldMap, foldr), find, foldl', for_, traverse_, any, all) -import Data.Traversable (Traversable (traverse, sequenceA), for) +import Data.Foldable (Foldable (foldMap, foldr), all, any, find, foldl', for_, traverse_) import qualified Data.Foldable +import Data.Traversable (Traversable (sequenceA, traverse), for) import Control.Applicative (Alternative (..)) -import Control.DeepSeq (NFData (..)) +import Control.DeepSeq (NFData (..), deepseq, force) +import Control.Exception (Exception (..), IOException, SomeException (..), catch, evaluate, throwIO) import Data.Data (Data) -import Distribution.Compat.Typeable (Typeable, TypeRep, typeRep) import Distribution.Compat.Binary (Binary (..)) import Distribution.Compat.Semigroup (Semigroup (..), gmappend, gmempty) -import GHC.Generics (Generic, Rep(..), - V1, U1(U1), K1(unK1), M1(unM1), - (:*:)((:*:)), (:+:)(L1,R1)) +import Distribution.Compat.Typeable (TypeRep, Typeable, typeRep) +import GHC.Generics ((:*:) ((:*:)), (:+:) (L1, R1), Generic, K1 (unK1), M1 (unM1), Rep (..), U1 (U1), V1) + -import Data.Functor.Identity (Identity (..)) -import Data.Map (Map) -import Data.Proxy (Proxy (..)) -import Data.Set (Set) +import Data.Functor.Identity (Identity (..)) +import Data.Map (Map) +import Data.Proxy (Proxy (..)) +import Data.Set (Set) -import Control.Arrow (first) -import Control.Monad hiding (mapM) +import Control.Applicative (Const (..)) +import Control.Arrow (first) +import Control.Monad hiding (mapM) import Data.Char -import Data.List (intercalate, intersperse, isPrefixOf, - isSuffixOf, nub, nubBy, sort, sortBy, - unfoldr) -import Data.List.NonEmpty (NonEmpty((:|)), head, tail, init, last) -import Data.Maybe -import Data.String (IsString (..)) +import Data.Either (partitionEithers) +import Data.Function (on) import Data.Int +import Data.List (intercalate, intersperse, isPrefixOf, isSuffixOf, nub, nubBy, partition, sort, sortBy, unfoldr) +import Data.List.NonEmpty (NonEmpty ((:|)), head, init, last, tail) +import Data.Maybe +import Data.Ord (comparing) +import Data.String (IsString (..)) +import Data.Void (Void, absurd, vacuous) import Data.Word -import Data.Void (Void, absurd, vacuous) -import Text.Read (readMaybe) +import System.Exit (ExitCode (..), exitFailure, exitSuccess, exitWith) +import Text.Read (readMaybe) import qualified Text.PrettyPrint as Disp -import Distribution.Utils.Structured (Structured) +import Distribution.Compat.Exception import Distribution.Compat.NonEmptySet (NonEmptySet) +import Distribution.Utils.Structured (Structured) + +import qualified Debug.Trace -- | New name for 'Text.PrettyPrint.<>' (<<>>) :: Disp.Doc -> Disp.Doc -> Disp.Doc @@ -258,3 +281,18 @@ foldr1 = Data.Foldable.foldr1 {-# INLINE foldl1 #-} foldl1 :: (a -> a -> a) -> NonEmpty a -> a foldl1 = Data.Foldable.foldl1 + +------------------------------------------------------------------------------- +-- Trace +------------------------------------------------------------------------------- + +-- Functions from Debug.Trace +-- but with DEPRECATED pragma, so -Werror will scream on them. + +traceShowId :: Show a => a -> a +traceShowId = Debug.Trace.traceShowId +{-# DEPRECATED traceShowId "Don't leave me in the code" #-} + +traceShow :: Show a => a -> b -> b +traceShow = Debug.Trace.traceShow +{-# DEPRECATED traceShow "Don't leave me in the code" #-} diff --git a/Cabal/Distribution/Compat/ResponseFile.hs b/Cabal/Distribution/Compat/ResponseFile.hs index 5ddfe57b99b..95bc0c818f8 100644 --- a/Cabal/Distribution/Compat/ResponseFile.hs +++ b/Cabal/Distribution/Compat/ResponseFile.hs @@ -5,10 +5,8 @@ -- http://hackage.haskell.org/package/base-4.12.0.0/src/LICENSE module Distribution.Compat.ResponseFile (expandResponse) where -import Prelude (mapM) import Distribution.Compat.Prelude -import System.Exit import System.FilePath import System.IO (hPutStrLn, stderr) import System.IO.Error @@ -57,7 +55,7 @@ expandResponse = go recursionLimit "." go :: Int -> FilePath -> [String] -> IO [String] go n dir - | n >= 0 = fmap concat . mapM (expand n dir) + | n >= 0 = fmap concat . traverse (expand n dir) | otherwise = const $ hPutStrLn stderr "Error: response file recursion limit exceeded." >> exitFailure expand :: Int -> FilePath -> String -> IO [String] diff --git a/Cabal/Distribution/FieldGrammar/Newtypes.hs b/Cabal/Distribution/FieldGrammar/Newtypes.hs index 1adc70f22ac..faa5820a31c 100644 --- a/Cabal/Distribution/FieldGrammar/Newtypes.hs +++ b/Cabal/Distribution/FieldGrammar/Newtypes.hs @@ -44,7 +44,7 @@ import Distribution.Parsec import Distribution.Pretty import Distribution.Version (LowerBound (..), Version, VersionRange, VersionRangeF (..), anyVersion, asVersionIntervals, cataVersionRange, mkVersion, version0, versionNumbers) -import Text.PrettyPrint (Doc, comma, fsep, punctuate, text, vcat, (<+>)) +import Text.PrettyPrint (Doc, comma, fsep, punctuate, text, vcat) import qualified Data.Set as Set import qualified Distribution.Compat.CharParsing as P diff --git a/Cabal/Distribution/FieldGrammar/Parsec.hs b/Cabal/Distribution/FieldGrammar/Parsec.hs index 01bbc541822..d0a64eb7f59 100644 --- a/Cabal/Distribution/FieldGrammar/Parsec.hs +++ b/Cabal/Distribution/FieldGrammar/Parsec.hs @@ -66,7 +66,6 @@ module Distribution.FieldGrammar.Parsec ( ) where import Data.List (dropWhileEnd) -import Data.Ord (comparing) import Distribution.Compat.Newtype import Distribution.Compat.Prelude import Distribution.Simple.Utils (fromUTF8BS) diff --git a/Cabal/Distribution/Fields/Parser.hs b/Cabal/Distribution/Fields/Parser.hs index d00d2c1d326..5c244ff513b 100644 --- a/Cabal/Distribution/Fields/Parser.hs +++ b/Cabal/Distribution/Fields/Parser.hs @@ -27,7 +27,6 @@ module Distribution.Fields.Parser ( #endif ) where -import Control.Monad (guard) import qualified Data.ByteString.Char8 as B8 import Data.Functor.Identity import Distribution.Compat.Prelude diff --git a/Cabal/Distribution/InstalledPackageInfo.hs b/Cabal/Distribution/InstalledPackageInfo.hs index 9e8cc8427a3..39700228b78 100644 --- a/Cabal/Distribution/InstalledPackageInfo.hs +++ b/Cabal/Distribution/InstalledPackageInfo.hs @@ -52,7 +52,6 @@ import Distribution.Package hiding (installedUnitId) import Distribution.Types.ComponentName import Distribution.Utils.Generic (toUTF8BS) -import Control.DeepSeq (deepseq) import Data.ByteString (ByteString) import qualified Data.Map as Map diff --git a/Cabal/Distribution/Make.hs b/Cabal/Distribution/Make.hs index cde201eb9c2..b5651d3b323 100644 --- a/Cabal/Distribution/Make.hs +++ b/Cabal/Distribution/Make.hs @@ -67,7 +67,6 @@ import Prelude () import Distribution.Compat.Prelude -- local -import Distribution.Compat.Exception import Distribution.Package import Distribution.Simple.Program import Distribution.Simple.Setup @@ -80,7 +79,6 @@ import Distribution.Version import Distribution.Pretty import System.Environment (getArgs, getProgName) -import System.Exit defaultMain :: IO () defaultMain = getArgs >>= defaultMainArgs diff --git a/Cabal/Distribution/PackageDescription/Check.hs b/Cabal/Distribution/PackageDescription/Check.hs index 44de045d5f8..7798722bc25 100644 --- a/Cabal/Distribution/PackageDescription/Check.hs +++ b/Cabal/Distribution/PackageDescription/Check.hs @@ -36,7 +36,6 @@ module Distribution.PackageDescription.Check ( import Distribution.Compat.Prelude import Prelude () -import Control.Monad (mapM) import Data.List (group) import Distribution.CabalSpecVersion import Distribution.Compat.Lens @@ -1842,7 +1841,7 @@ checkLicensesExist :: Monad m => CheckPackageContentOps m -> PackageDescription -> m [PackageCheck] checkLicensesExist ops pkg = do - exists <- mapM (doesFileExist ops) (licenseFiles pkg) + exists <- traverse (doesFileExist ops) (licenseFiles pkg) return [ PackageBuildWarning $ "The '" ++ fieldname ++ "' field refers to the file " @@ -1899,7 +1898,7 @@ checkMissingVcsInfo :: Monad m => CheckPackageContentOps m -> PackageDescription -> m [PackageCheck] checkMissingVcsInfo ops pkg | null (sourceRepos pkg) = do - vcsInUse <- liftM or $ mapM (doesDirectoryExist ops) repoDirnames + vcsInUse <- liftM or $ traverse (doesDirectoryExist ops) repoDirnames if vcsInUse then return [ PackageDistSuspicious message ] else return [] diff --git a/Cabal/Distribution/PackageDescription/Parsec.hs b/Cabal/Distribution/PackageDescription/Parsec.hs index 74d6ede0de6..363cb9e2b0f 100644 --- a/Cabal/Distribution/PackageDescription/Parsec.hs +++ b/Cabal/Distribution/PackageDescription/Parsec.hs @@ -35,12 +35,8 @@ module Distribution.PackageDescription.Parsec ( import Distribution.Compat.Prelude import Prelude () -import Control.Applicative (Const (..)) -import Control.DeepSeq (deepseq) -import Control.Monad (guard) import Control.Monad.State.Strict (StateT, execStateT) import Control.Monad.Trans.Class (lift) -import Data.List (partition) import Distribution.CabalSpecVersion import Distribution.Compat.Lens import Distribution.FieldGrammar diff --git a/Cabal/Distribution/PackageDescription/PrettyPrint.hs b/Cabal/Distribution/PackageDescription/PrettyPrint.hs index a81faf64658..e5e89d93502 100644 --- a/Cabal/Distribution/PackageDescription/PrettyPrint.hs +++ b/Cabal/Distribution/PackageDescription/PrettyPrint.hs @@ -51,7 +51,7 @@ import Distribution.PackageDescription.FieldGrammar import qualified Distribution.PackageDescription.FieldGrammar as FG -import Text.PrettyPrint (Doc, char, hsep, parens, text, (<+>)) +import Text.PrettyPrint (Doc, char, hsep, parens, text) import qualified Data.ByteString.Lazy.Char8 as BS.Char8 diff --git a/Cabal/Distribution/SPDX/LicenseExpression.hs b/Cabal/Distribution/SPDX/LicenseExpression.hs index 6cc7dab7dab..a59e386e1f3 100644 --- a/Cabal/Distribution/SPDX/LicenseExpression.hs +++ b/Cabal/Distribution/SPDX/LicenseExpression.hs @@ -16,7 +16,6 @@ import Distribution.SPDX.LicenseId import Distribution.SPDX.LicenseListVersion import Distribution.SPDX.LicenseReference import Distribution.Utils.Generic (isAsciiAlphaNum) -import Text.PrettyPrint ((<+>)) import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index 0d2f34746a6..5543765a10d 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -98,7 +98,6 @@ import Distribution.System (buildPlatform) import System.Environment (getArgs, getProgName) import System.Directory (removeFile, doesFileExist ,doesDirectoryExist, removeDirectoryRecursive) -import System.Exit (exitWith,ExitCode(..)) import System.FilePath (searchPathSeparator, takeDirectory, (), splitDirectories, dropDrive) import Distribution.Compat.ResponseFile (expandResponse) import Distribution.Compat.Directory (makeAbsolute) diff --git a/Cabal/Distribution/Simple/Bench.hs b/Cabal/Distribution/Simple/Bench.hs index ab76e69e2f7..936638c3a4d 100644 --- a/Cabal/Distribution/Simple/Bench.hs +++ b/Cabal/Distribution/Simple/Bench.hs @@ -32,7 +32,6 @@ import Distribution.Simple.UserHooks import Distribution.Simple.Utils import Distribution.Pretty -import System.Exit ( ExitCode(..), exitFailure, exitSuccess ) import System.Directory ( doesFileExist ) import System.FilePath ( (), (<.>) ) diff --git a/Cabal/Distribution/Simple/BuildTarget.hs b/Cabal/Distribution/Simple/BuildTarget.hs index 0f0c81085ee..0b367db9ac8 100644 --- a/Cabal/Distribution/Simple/BuildTarget.hs +++ b/Cabal/Distribution/Simple/BuildTarget.hs @@ -57,9 +57,8 @@ import Distribution.Verbosity import qualified Distribution.Compat.CharParsing as P import Control.Monad ( msum ) -import Data.List ( stripPrefix, groupBy, partition ) +import Data.List ( stripPrefix, groupBy ) import qualified Data.List.NonEmpty as NE -import Data.Either ( partitionEithers ) import System.FilePath as FilePath ( dropExtension, normalise, splitDirectories, joinPath, splitPath , hasTrailingPathSeparator ) diff --git a/Cabal/Distribution/Simple/Compiler.hs b/Cabal/Distribution/Simple/Compiler.hs index 976c6438b9f..e2607405e3a 100644 --- a/Cabal/Distribution/Simple/Compiler.hs +++ b/Cabal/Distribution/Simple/Compiler.hs @@ -80,7 +80,6 @@ import Distribution.Version import Language.Haskell.Extension import Distribution.Simple.Utils -import Control.Monad (join) import qualified Data.Map as Map (lookup) import System.Directory (canonicalizePath) diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 3f7b53f61ce..a7d078d17e4 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -54,7 +54,7 @@ module Distribution.Simple.Configure , platformDefines, ) where -import qualified Prelude (tail) +import qualified Prelude as Unsafe (tail) import Distribution.Compat.Prelude import Distribution.Compiler @@ -112,8 +112,7 @@ import qualified Distribution.Simple.UHC as UHC import qualified Distribution.Simple.HaskellSuite as HaskellSuite import Control.Exception - ( ErrorCall, Exception, evaluate, throw, throwIO, try ) -import Control.Monad ( forM, forM_ ) + ( try ) import Data.List.NonEmpty ( nonEmpty ) import Distribution.Utils.Structured ( structuredDecodeOrFailIO, structuredEncode ) import Distribution.Compat.Directory ( listDirectory ) @@ -121,9 +120,7 @@ import Data.ByteString.Lazy ( ByteString ) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy.Char8 as BLC8 import Data.List - ( (\\), partition, inits, stripPrefix, intersect, dropWhileEnd ) -import Data.Either - ( partitionEithers ) + ( (\\), inits, stripPrefix, intersect, dropWhileEnd ) import qualified Data.Map as Map import System.Directory ( canonicalizePath, createDirectoryIfMissing, doesFileExist @@ -141,10 +138,9 @@ import Distribution.Pretty import Distribution.Parsec ( simpleParsec ) import Text.PrettyPrint - ( Doc, (<+>), ($+$), char, comma, hsep, nest + ( Doc, ($+$), char, comma, hsep, nest , punctuate, quotes, render, renderStyle, sep, text ) import Distribution.Compat.Environment ( lookupEnv ) -import Distribution.Compat.Exception ( catchExit, catchIO ) import qualified Distribution.Compat.NonEmptySet as NonEmptySet @@ -206,21 +202,17 @@ getConfigStateFile filename = do contents <- BS.readFile filename let (header, body) = BLC8.span (/='\n') (BLC8.fromChunks [contents]) - headerParseResult <- try $ evaluate $ parseHeader header - let (cabalId, compId) = - case headerParseResult of - Left (_ :: ErrorCall) -> throw ConfigStateFileBadHeader - Right x -> x + (cabalId, compId) <- parseHeader header let getStoredValue = do result <- structuredDecodeOrFailIO (BLC8.tail body) case result of - Left _ -> throw ConfigStateFileNoParse + Left _ -> throwIO ConfigStateFileNoParse Right x -> return x deferErrorIfBadVersion act | cabalId /= currentCabalId = do eResult <- try act - throw $ ConfigStateFileBadVersion cabalId compId eResult + throwIO $ ConfigStateFileBadVersion cabalId compId eResult | otherwise = act deferErrorIfBadVersion getStoredValue where @@ -274,16 +266,16 @@ currentCompilerId = PackageIdentifier (mkPackageName System.Info.compilerName) -- | Parse the @setup-config@ file header, returning the package identifiers -- for Cabal and the compiler. parseHeader :: ByteString -- ^ The file contents. - -> (PackageIdentifier, PackageIdentifier) + -> IO (PackageIdentifier, PackageIdentifier) parseHeader header = case BLC8.words header of ["Saved", "package", "config", "for", pkgId, "written", "by", cabalId, "using", compId] -> - fromMaybe (throw ConfigStateFileBadHeader) $ do + maybe (throwIO ConfigStateFileBadHeader) return $ do _ <- simpleParsec (fromUTF8LBS pkgId) :: Maybe PackageIdentifier cabalId' <- simpleParsec (BLC8.unpack cabalId) compId' <- simpleParsec (BLC8.unpack compId) return (cabalId', compId') - _ -> throw ConfigStateFileNoHeader + _ -> throwIO ConfigStateFileNoHeader -- | Generate the @setup-config@ file header. showHeader :: PackageIdentifier -- ^ The processed package. @@ -1758,14 +1750,14 @@ checkForeignDeps pkg lbi verbosity = checkDuplicateHeaders = do let relIncDirs = filter (not . isAbsolute) (collectField includeDirs) isHeader = isSuffixOf ".h" - genHeaders <- forM relIncDirs $ \dir -> + genHeaders <- for relIncDirs $ \dir -> fmap (dir ) . filter isHeader <$> listDirectory (buildDir lbi dir) `catchIO` (\_ -> return []) - srcHeaders <- forM relIncDirs $ \dir -> + srcHeaders <- for relIncDirs $ \dir -> fmap (dir ) . filter isHeader <$> listDirectory (baseDir lbi dir) `catchIO` (\_ -> return []) let commonHeaders = concat genHeaders `intersect` concat srcHeaders - forM_ commonHeaders $ \hdr -> do + for_ commonHeaders $ \hdr -> do warn verbosity $ "Duplicate header found in " ++ (buildDir lbi hdr) ++ " and " @@ -1777,7 +1769,7 @@ checkForeignDeps pkg lbi verbosity = findOffendingHdr = ifBuildsWith allHeaders ccArgs (return Nothing) - (go . Prelude.tail . inits $ allHeaders) -- inits always contains at least [] + (go . Unsafe.tail . inits $ allHeaders) -- inits always contains at least [] where go [] = return Nothing -- cannot happen go (hdrs:hdrsInits) = @@ -2014,7 +2006,7 @@ checkRelocatable verbosity pkg lbi where doCheck pkgr ipkg | maybe False (== pkgr) (IPI.pkgRoot ipkg) - = forM_ (IPI.libraryDirs ipkg) $ \libdir -> do + = for_ (IPI.libraryDirs ipkg) $ \libdir -> do -- When @prefix@ is not under @pkgroot@, -- @shortRelativePath prefix pkgroot@ will return a path with -- @..@s and following check will fail without @canonicalizePath@. diff --git a/Cabal/Distribution/Simple/GHC/EnvironmentParser.hs b/Cabal/Distribution/Simple/GHC/EnvironmentParser.hs index 0e2cea27e8f..f0ff8bc9cba 100644 --- a/Cabal/Distribution/Simple/GHC/EnvironmentParser.hs +++ b/Cabal/Distribution/Simple/GHC/EnvironmentParser.hs @@ -17,8 +17,6 @@ import Distribution.Simple.GHC.Internal import Distribution.Types.UnitId ( mkUnitId ) -import Control.Exception - ( Exception, throwIO ) import qualified Text.Parsec as P import Text.Parsec.String ( Parser, parseFromFile ) diff --git a/Cabal/Distribution/Simple/GHC/Internal.hs b/Cabal/Distribution/Simple/GHC/Internal.hs index b62288c9370..36fdb1a027f 100644 --- a/Cabal/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/Distribution/Simple/GHC/Internal.hs @@ -53,7 +53,6 @@ import Distribution.Types.ComponentLocalBuildInfo import Distribution.Backpack import qualified Distribution.InstalledPackageInfo as IPI import Distribution.PackageDescription -import Distribution.Compat.Exception import Distribution.Lex import Distribution.Simple.Compiler import Distribution.Simple.Program.GHC @@ -669,9 +668,9 @@ renderGhcEnvironmentFile = renderGhcEnvironmentFileEntry :: GhcEnvironmentFileEntry -> String renderGhcEnvironmentFileEntry entry = case entry of GhcEnvFileComment comment -> format comment - where format = intercalate "\n" . map ("--" <+>) . lines - pref <+> "" = pref - pref <+> str = pref ++ " " ++ str + where format = intercalate "\n" . map ("--" <++>) . lines + pref <++> "" = pref + pref <++> str = pref ++ " " ++ str GhcEnvFilePackageId pkgid -> "package-id " ++ prettyShow pkgid GhcEnvFilePackageDb pkgdb -> case pkgdb of diff --git a/Cabal/Distribution/Simple/Glob.hs b/Cabal/Distribution/Simple/Glob.hs index 64066160e9e..6b0e1c2a6f8 100644 --- a/Cabal/Distribution/Simple/Glob.hs +++ b/Cabal/Distribution/Simple/Glob.hs @@ -28,8 +28,6 @@ module Distribution.Simple.Glob ( import Prelude () import Distribution.Compat.Prelude -import Control.Monad (guard) - import Distribution.CabalSpecVersion import Distribution.Simple.Utils import Distribution.Verbosity diff --git a/Cabal/Distribution/Simple/HaskellSuite.hs b/Cabal/Distribution/Simple/HaskellSuite.hs index 567a3428149..a58f1a524b8 100644 --- a/Cabal/Distribution/Simple/HaskellSuite.hs +++ b/Cabal/Distribution/Simple/HaskellSuite.hs @@ -6,9 +6,6 @@ module Distribution.Simple.HaskellSuite where import Prelude () import Distribution.Compat.Prelude -import Data.Either (partitionEithers) - -import qualified Data.Map as Map (empty) import qualified Data.List.NonEmpty as NE import Distribution.Simple.Program @@ -25,7 +22,6 @@ import Distribution.Simple.PackageIndex as PackageIndex import Distribution.PackageDescription import Distribution.Simple.LocalBuildInfo import Distribution.System (Platform) -import Distribution.Compat.Exception import Language.Haskell.Extension import Distribution.Simple.Program.Builtin @@ -83,7 +79,7 @@ configure verbosity mbHcPath hcPkgPath progdb0 = do compilerCompat = [], compilerLanguages = languages, compilerExtensions = extensions, - compilerProperties = Map.empty + compilerProperties = mempty } return (comp, confdCompiler, progdb2) diff --git a/Cabal/Distribution/Simple/Program/Builtin.hs b/Cabal/Distribution/Simple/Program/Builtin.hs index 8e723ac0ec5..ba3727c0c88 100644 --- a/Cabal/Distribution/Simple/Program/Builtin.hs +++ b/Cabal/Distribution/Simple/Program/Builtin.hs @@ -54,7 +54,6 @@ import Distribution.Simple.Program.Internal import Distribution.Simple.Program.Run import Distribution.Simple.Program.Types import Distribution.Simple.Utils -import Distribution.Compat.Exception import Distribution.Verbosity import Distribution.Version diff --git a/Cabal/Distribution/Simple/Program/Db.hs b/Cabal/Distribution/Simple/Program/Db.hs index ec56ad803a5..4657e19b059 100644 --- a/Cabal/Distribution/Simple/Program/Db.hs +++ b/Cabal/Distribution/Simple/Program/Db.hs @@ -73,8 +73,7 @@ import Distribution.Utils.Structured (Structure (..), Structured (..)) import Distribution.Verbosity import Distribution.Version -import Control.Monad (join) -import Data.Tuple (swap) +import Data.Tuple (swap) import qualified Data.Map as Map diff --git a/Cabal/Distribution/Simple/Program/HcPkg.hs b/Cabal/Distribution/Simple/Program/HcPkg.hs index 1e7f83feb79..3f254c6c335 100644 --- a/Cabal/Distribution/Simple/Program/HcPkg.hs +++ b/Cabal/Distribution/Simple/Program/HcPkg.hs @@ -47,7 +47,6 @@ module Distribution.Simple.Program.HcPkg ( import Distribution.Compat.Prelude hiding (init) import Prelude () -import Distribution.Compat.Exception import Distribution.InstalledPackageInfo import Distribution.Parsec import Distribution.Pretty diff --git a/Cabal/Distribution/Simple/Program/Hpc.hs b/Cabal/Distribution/Simple/Program/Hpc.hs index 152e382ac4a..bcc64e39913 100644 --- a/Cabal/Distribution/Simple/Program/Hpc.hs +++ b/Cabal/Distribution/Simple/Program/Hpc.hs @@ -19,7 +19,6 @@ module Distribution.Simple.Program.Hpc import Prelude () import Distribution.Compat.Prelude -import Control.Monad (mapM) import System.Directory (makeRelativeToCurrentDirectory) import Distribution.ModuleName @@ -61,7 +60,7 @@ markup hpc hpcVer verbosity tixFile hpcDirs destDir excluded = do return passedDirs -- Prior to GHC 8.0, hpc assumes all .mix paths are relative. - hpcDirs'' <- mapM makeRelativeToCurrentDirectory hpcDirs' + hpcDirs'' <- traverse makeRelativeToCurrentDirectory hpcDirs' runProgramInvocation verbosity (markupInvocation hpc tixFile hpcDirs'' destDir excluded) diff --git a/Cabal/Distribution/Simple/Program/Run.hs b/Cabal/Distribution/Simple/Program/Run.hs index ce782f098e5..91ab9691bee 100644 --- a/Cabal/Distribution/Simple/Program/Run.hs +++ b/Cabal/Distribution/Simple/Program/Run.hs @@ -38,8 +38,7 @@ import Distribution.Simple.Utils import Distribution.Utils.Generic import Distribution.Verbosity -import System.Exit (ExitCode (..), exitWith) -import System.FilePath +import System.FilePath (searchPathSeparator) import qualified Data.ByteString.Lazy as LBS import qualified Data.Map as Map diff --git a/Cabal/Distribution/Simple/Register.hs b/Cabal/Distribution/Simple/Register.hs index ea6237d3445..6c05ef79d70 100644 --- a/Cabal/Distribution/Simple/Register.hs +++ b/Cabal/Distribution/Simple/Register.hs @@ -87,7 +87,6 @@ import Distribution.Compat.Graph (IsNode(nodeKey)) import System.FilePath ((), (<.>), isAbsolute) import System.Directory -import Data.List (partition) import qualified Data.ByteString.Lazy.Char8 as BS.Char8 -- ----------------------------------------------------------------------------- diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index e8295f8387e..f7b2a9b8c2e 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -108,8 +108,6 @@ import Distribution.Types.UnqualComponentName (unUnqualComponentName) import Distribution.Compat.Stack import Distribution.Compat.Semigroup (Last' (..), Option' (..)) -import Data.Function (on) - -- FIXME Not sure where this should live defaultDistPref :: FilePath defaultDistPref = "dist" diff --git a/Cabal/Distribution/Simple/SrcDist.hs b/Cabal/Distribution/Simple/SrcDist.hs index 60bf9414aeb..3b6c40e1d95 100644 --- a/Cabal/Distribution/Simple/SrcDist.hs +++ b/Cabal/Distribution/Simple/SrcDist.hs @@ -64,13 +64,11 @@ import Distribution.Pretty import Distribution.Types.ForeignLib import Distribution.Verbosity -import Data.List (partition) import qualified Data.Map as Map import Data.Time (UTCTime, getCurrentTime, toGregorian, utctDay) import System.Directory ( doesFileExist ) import System.IO (IOMode(WriteMode), hPutStrLn, withFile) import System.FilePath ((), (<.>), dropExtension, isRelative) -import Control.Monad -- |Create a source distribution. sdist :: PackageDescription -- ^ information from the tarball @@ -189,7 +187,7 @@ listPackageSources' verbosity rip cwd pkg_descr pps = , fmap concat . withAllFLib $ \flib@(ForeignLib { foreignLibBuildInfo = flibBi }) -> do biSrcs <- allSourcesBuildInfo verbosity rip cwd flibBi pps [] - defFiles <- mapM (findModDefFile verbosity cwd flibBi pps) + defFiles <- traverse (findModDefFile verbosity cwd flibBi pps) (foreignLibModDefFile flib) return (defFiles ++ biSrcs) diff --git a/Cabal/Distribution/Simple/Test.hs b/Cabal/Distribution/Simple/Test.hs index 5547c737988..85c2e9d4fd2 100644 --- a/Cabal/Distribution/Simple/Test.hs +++ b/Cabal/Distribution/Simple/Test.hs @@ -40,7 +40,6 @@ import Distribution.Pretty import System.Directory ( createDirectoryIfMissing, doesFileExist, getDirectoryContents , removeFile ) -import System.Exit ( exitFailure, exitSuccess ) import System.FilePath ( () ) -- |Perform the \"@.\/setup test@\" action. diff --git a/Cabal/Distribution/Simple/Test/ExeV10.hs b/Cabal/Distribution/Simple/Test/ExeV10.hs index a6861986a16..f242bf6e1fe 100644 --- a/Cabal/Distribution/Simple/Test/ExeV10.hs +++ b/Cabal/Distribution/Simple/Test/ExeV10.hs @@ -31,7 +31,6 @@ import Control.Concurrent (forkIO) import System.Directory ( createDirectoryIfMissing, doesDirectoryExist, doesFileExist , getCurrentDirectory, removeDirectoryRecursive ) -import System.Exit ( ExitCode(..) ) import System.FilePath ( (), (<.>) ) import System.IO ( hGetContents, stdout, stderr ) diff --git a/Cabal/Distribution/Simple/Test/LibV09.hs b/Cabal/Distribution/Simple/Test/LibV09.hs index cd9d0dc19c3..f9ebc9e1140 100644 --- a/Cabal/Distribution/Simple/Test/LibV09.hs +++ b/Cabal/Distribution/Simple/Test/LibV09.hs @@ -39,7 +39,6 @@ import System.Directory , doesDirectoryExist, doesFileExist , getCurrentDirectory, removeDirectoryRecursive, removeFile , setCurrentDirectory ) -import System.Exit ( exitSuccess, exitWith, ExitCode(..) ) import System.FilePath ( (), (<.>) ) import System.IO ( hClose, hGetContents, hPutStr ) import System.Process (StdStream(..), waitForProcess) diff --git a/Cabal/Distribution/Simple/Utils.hs b/Cabal/Distribution/Simple/Utils.hs index 1b1fa4938d1..d7c55951b39 100644 --- a/Cabal/Distribution/Simple/Utils.hs +++ b/Cabal/Distribution/Simple/Utils.hs @@ -188,7 +188,6 @@ import Distribution.Version import Distribution.Compat.Async import Distribution.Compat.CopyFile import Distribution.Compat.Internal.TempFile -import Distribution.Compat.Exception import Distribution.Compat.FilePath as FilePath import Distribution.Compat.Stack import Distribution.Verbosity @@ -221,8 +220,6 @@ import System.Directory , getModificationTime, createDirectory, removeDirectoryRecursive ) import System.Environment ( getProgName ) -import System.Exit - ( exitWith, ExitCode(..) ) import System.FilePath as FilePath ( normalise, (), (<.>) , getSearchPath, joinPath, takeDirectory, splitExtension @@ -237,7 +234,6 @@ import qualified Control.Exception as Exception import Foreign.C.Error (Errno (..), ePIPE) import Data.Time.Clock.POSIX (getPOSIXTime, POSIXTime) -import Control.Exception (IOException, evaluate, throwIO, fromException) import Numeric (showFFloat) import Distribution.Compat.Process (createProcess, rawSystem, runInteractiveProcess) import System.Process diff --git a/Cabal/Distribution/Types/Dependency.hs b/Cabal/Distribution/Types/Dependency.hs index 2e4a115d25e..8170f2b3db2 100644 --- a/Cabal/Distribution/Types/Dependency.hs +++ b/Cabal/Distribution/Types/Dependency.hs @@ -24,7 +24,6 @@ import Distribution.Pretty import Distribution.Types.LibraryName import Distribution.Types.PackageName import Distribution.Types.UnqualComponentName -import Text.PrettyPrint ((<+>)) import qualified Distribution.Compat.NonEmptySet as NonEmptySet import qualified Text.PrettyPrint as PP diff --git a/Cabal/Distribution/Types/IncludeRenaming.hs b/Cabal/Distribution/Types/IncludeRenaming.hs index f59d45e1f72..0b313912a8d 100644 --- a/Cabal/Distribution/Types/IncludeRenaming.hs +++ b/Cabal/Distribution/Types/IncludeRenaming.hs @@ -15,7 +15,7 @@ import Distribution.Types.ModuleRenaming import qualified Distribution.Compat.CharParsing as P import Distribution.Parsec import Distribution.Pretty -import Text.PrettyPrint (text, (<+>)) +import Text.PrettyPrint (text) import qualified Text.PrettyPrint as Disp -- --------------------------------------------------------------------------- diff --git a/Cabal/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs b/Cabal/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs index d8c28772cc7..e36da452cbb 100644 --- a/Cabal/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs +++ b/Cabal/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs @@ -47,10 +47,10 @@ import qualified Distribution.Types.PackageId.Lens as L -- https://ghc.haskell.org/trac/ghc/ticket/13253 might be the cause. -- -- The workaround is to prevent GHC optimising the code: -infixl 4 <+> -(<+>) :: Applicative f => f (a -> b) -> f a -> f b -f <+> x = f <*> x -{-# NOINLINE (<+>) #-} +infixl 4 <@> +(<@>) :: Applicative f => f (a -> b) -> f a -> f b +f <@> x = f <*> x +{-# NOINLINE (<@>) #-} ipiFieldGrammar :: ( FieldGrammar c g, Applicative (g InstalledPackageInfo), Applicative (g Basic) @@ -78,47 +78,47 @@ ipiFieldGrammar = mkInstalledPackageInfo --- https://github.com/haskell/cabal/commit/40f3601e17024f07e0da8e64d3dd390177ce908b ^^^ deprecatedSince CabalSpecV1_22 "hugs isn't supported anymore" -- Very basic fields: name, version, package-name, lib-name and visibility - <+> blurFieldGrammar basic basicFieldGrammar + <@> blurFieldGrammar basic basicFieldGrammar -- Basic fields - <+> optionalFieldDef "id" L.installedUnitId (mkUnitId "") - <+> optionalFieldDefAla "instantiated-with" InstWith L.instantiatedWith [] - <+> optionalFieldDefAla "key" CompatPackageKey L.compatPackageKey "" - <+> optionalFieldDefAla "license" SpecLicenseLenient L.license (Left SPDX.NONE) - <+> freeTextFieldDefST "copyright" L.copyright - <+> freeTextFieldDefST "maintainer" L.maintainer - <+> freeTextFieldDefST "author" L.author - <+> freeTextFieldDefST "stability" L.stability - <+> freeTextFieldDefST "homepage" L.homepage - <+> freeTextFieldDefST "package-url" L.pkgUrl - <+> freeTextFieldDefST "synopsis" L.synopsis - <+> freeTextFieldDefST "description" L.description - <+> freeTextFieldDefST "category" L.category + <@> optionalFieldDef "id" L.installedUnitId (mkUnitId "") + <@> optionalFieldDefAla "instantiated-with" InstWith L.instantiatedWith [] + <@> optionalFieldDefAla "key" CompatPackageKey L.compatPackageKey "" + <@> optionalFieldDefAla "license" SpecLicenseLenient L.license (Left SPDX.NONE) + <@> freeTextFieldDefST "copyright" L.copyright + <@> freeTextFieldDefST "maintainer" L.maintainer + <@> freeTextFieldDefST "author" L.author + <@> freeTextFieldDefST "stability" L.stability + <@> freeTextFieldDefST "homepage" L.homepage + <@> freeTextFieldDefST "package-url" L.pkgUrl + <@> freeTextFieldDefST "synopsis" L.synopsis + <@> freeTextFieldDefST "description" L.description + <@> freeTextFieldDefST "category" L.category -- Installed fields - <+> optionalFieldDef "abi" L.abiHash (mkAbiHash "") - <+> booleanFieldDef "indefinite" L.indefinite False - <+> booleanFieldDef "exposed" L.exposed False - <+> monoidalFieldAla "exposed-modules" ExposedModules L.exposedModules - <+> monoidalFieldAla "hidden-modules" (alaList' FSep MQuoted) L.hiddenModules - <+> booleanFieldDef "trusted" L.trusted False - <+> monoidalFieldAla "import-dirs" (alaList' FSep FilePathNT) L.importDirs - <+> monoidalFieldAla "library-dirs" (alaList' FSep FilePathNT) L.libraryDirs - <+> monoidalFieldAla "dynamic-library-dirs" (alaList' FSep FilePathNT) L.libraryDynDirs - <+> optionalFieldDefAla "data-dir" FilePathNT L.dataDir "" - <+> monoidalFieldAla "hs-libraries" (alaList' FSep Token) L.hsLibraries - <+> monoidalFieldAla "extra-libraries" (alaList' FSep Token) L.extraLibraries - <+> monoidalFieldAla "extra-ghci-libraries" (alaList' FSep Token) L.extraGHCiLibraries - <+> monoidalFieldAla "include-dirs" (alaList' FSep FilePathNT) L.includeDirs - <+> monoidalFieldAla "includes" (alaList' FSep FilePathNT) L.includes - <+> monoidalFieldAla "depends" (alaList FSep) L.depends - <+> monoidalFieldAla "abi-depends" (alaList FSep) L.abiDepends - <+> monoidalFieldAla "cc-options" (alaList' FSep Token) L.ccOptions - <+> monoidalFieldAla "cxx-options" (alaList' FSep Token) L.cxxOptions - <+> monoidalFieldAla "ld-options" (alaList' FSep Token) L.ldOptions - <+> monoidalFieldAla "framework-dirs" (alaList' FSep FilePathNT) L.frameworkDirs - <+> monoidalFieldAla "frameworks" (alaList' FSep Token) L.frameworks - <+> monoidalFieldAla "haddock-interfaces" (alaList' FSep FilePathNT) L.haddockInterfaces - <+> monoidalFieldAla "haddock-html" (alaList' FSep FilePathNT) L.haddockHTMLs - <+> optionalFieldAla "pkgroot" FilePathNT L.pkgRoot + <@> optionalFieldDef "abi" L.abiHash (mkAbiHash "") + <@> booleanFieldDef "indefinite" L.indefinite False + <@> booleanFieldDef "exposed" L.exposed False + <@> monoidalFieldAla "exposed-modules" ExposedModules L.exposedModules + <@> monoidalFieldAla "hidden-modules" (alaList' FSep MQuoted) L.hiddenModules + <@> booleanFieldDef "trusted" L.trusted False + <@> monoidalFieldAla "import-dirs" (alaList' FSep FilePathNT) L.importDirs + <@> monoidalFieldAla "library-dirs" (alaList' FSep FilePathNT) L.libraryDirs + <@> monoidalFieldAla "dynamic-library-dirs" (alaList' FSep FilePathNT) L.libraryDynDirs + <@> optionalFieldDefAla "data-dir" FilePathNT L.dataDir "" + <@> monoidalFieldAla "hs-libraries" (alaList' FSep Token) L.hsLibraries + <@> monoidalFieldAla "extra-libraries" (alaList' FSep Token) L.extraLibraries + <@> monoidalFieldAla "extra-ghci-libraries" (alaList' FSep Token) L.extraGHCiLibraries + <@> monoidalFieldAla "include-dirs" (alaList' FSep FilePathNT) L.includeDirs + <@> monoidalFieldAla "includes" (alaList' FSep FilePathNT) L.includes + <@> monoidalFieldAla "depends" (alaList FSep) L.depends + <@> monoidalFieldAla "abi-depends" (alaList FSep) L.abiDepends + <@> monoidalFieldAla "cc-options" (alaList' FSep Token) L.ccOptions + <@> monoidalFieldAla "cxx-options" (alaList' FSep Token) L.cxxOptions + <@> monoidalFieldAla "ld-options" (alaList' FSep Token) L.ldOptions + <@> monoidalFieldAla "framework-dirs" (alaList' FSep FilePathNT) L.frameworkDirs + <@> monoidalFieldAla "frameworks" (alaList' FSep Token) L.frameworks + <@> monoidalFieldAla "haddock-interfaces" (alaList' FSep FilePathNT) L.haddockInterfaces + <@> monoidalFieldAla "haddock-html" (alaList' FSep FilePathNT) L.haddockHTMLs + <@> optionalFieldAla "pkgroot" FilePathNT L.pkgRoot where mkInstalledPackageInfo _ Basic {..} = InstalledPackageInfo -- _basicPkgName is not used @@ -297,7 +297,7 @@ basicFieldGrammar = mkBasic <*> optionalFieldDefAla "version" MQuoted basicVersion nullVersion <*> optionalField "package-name" basicPkgName <*> optionalField "lib-name" basicLibName - <+> optionalFieldDef "visibility" basicLibVisibility LibraryVisibilityPrivate + <*> optionalFieldDef "visibility" basicLibVisibility LibraryVisibilityPrivate where mkBasic n v pn ln lv = Basic n v pn ln' lv' where diff --git a/Cabal/Distribution/Types/LegacyExeDependency.hs b/Cabal/Distribution/Types/LegacyExeDependency.hs index ac43ea83754..775a7a99de9 100644 --- a/Cabal/Distribution/Types/LegacyExeDependency.hs +++ b/Cabal/Distribution/Types/LegacyExeDependency.hs @@ -12,7 +12,7 @@ import Distribution.Pretty import Distribution.Version (VersionRange, anyVersion) import qualified Distribution.Compat.CharParsing as P -import Text.PrettyPrint (text, (<+>)) +import qualified Text.PrettyPrint as Disp -- | Describes a legacy `build-tools`-style dependency on an executable -- @@ -31,8 +31,8 @@ instance Structured LegacyExeDependency instance NFData LegacyExeDependency where rnf = genericRnf instance Pretty LegacyExeDependency where - pretty (LegacyExeDependency name ver) = - text name <+> pretty ver + pretty (LegacyExeDependency name ver) = + Disp.text name <+> pretty ver instance Parsec LegacyExeDependency where parsec = do diff --git a/Cabal/Distribution/Types/Mixin.hs b/Cabal/Distribution/Types/Mixin.hs index 47201a6e1ac..404388e4ce3 100644 --- a/Cabal/Distribution/Types/Mixin.hs +++ b/Cabal/Distribution/Types/Mixin.hs @@ -8,8 +8,6 @@ module Distribution.Types.Mixin ( import Distribution.Compat.Prelude import Prelude () -import Text.PrettyPrint ((<+>)) - import Distribution.Parsec import Distribution.Pretty import Distribution.Types.IncludeRenaming diff --git a/Cabal/Distribution/Types/ModuleReexport.hs b/Cabal/Distribution/Types/ModuleReexport.hs index 635529abf8a..d209a68776a 100644 --- a/Cabal/Distribution/Types/ModuleReexport.hs +++ b/Cabal/Distribution/Types/ModuleReexport.hs @@ -14,8 +14,7 @@ import Distribution.Pretty import Distribution.Types.PackageName import qualified Distribution.Compat.CharParsing as P -import Text.PrettyPrint ((<+>)) -import qualified Text.PrettyPrint as Disp +import qualified Text.PrettyPrint as Disp -- ----------------------------------------------------------------------------- -- Module re-exports diff --git a/Cabal/Distribution/Types/ModuleRenaming.hs b/Cabal/Distribution/Types/ModuleRenaming.hs index 75b4ae2ecb0..581d45b9938 100644 --- a/Cabal/Distribution/Types/ModuleRenaming.hs +++ b/Cabal/Distribution/Types/ModuleRenaming.hs @@ -20,7 +20,7 @@ import Distribution.Pretty import qualified Data.Map as Map import qualified Data.Set as Set import qualified Distribution.Compat.CharParsing as P -import Text.PrettyPrint (hsep, parens, punctuate, text, (<+>), comma) +import Text.PrettyPrint (hsep, parens, punctuate, text, comma) -- | Renaming applied to the modules provided by a package. -- The boolean indicates whether or not to also include all of the diff --git a/Cabal/Distribution/Types/PackageVersionConstraint.hs b/Cabal/Distribution/Types/PackageVersionConstraint.hs index 0f3e8b72329..b70e6faf1a6 100644 --- a/Cabal/Distribution/Types/PackageVersionConstraint.hs +++ b/Cabal/Distribution/Types/PackageVersionConstraint.hs @@ -18,7 +18,6 @@ import Distribution.Types.VersionRange.Internal import Distribution.Version (simplifyVersionRange) import qualified Distribution.Compat.CharParsing as P -import Text.PrettyPrint ((<+>)) -- | A version constraint on a package. Different from 'ExeDependency' and -- 'Dependency' since it does not specify the need for a component, not even diff --git a/Cabal/Distribution/Types/PkgconfigDependency.hs b/Cabal/Distribution/Types/PkgconfigDependency.hs index 219a608a331..8b452cb7b40 100644 --- a/Cabal/Distribution/Types/PkgconfigDependency.hs +++ b/Cabal/Distribution/Types/PkgconfigDependency.hs @@ -14,7 +14,6 @@ import Distribution.Parsec import Distribution.Pretty import qualified Distribution.Compat.CharParsing as P -import Text.PrettyPrint ((<+>)) -- | Describes a dependency on a pkg-config library -- diff --git a/Cabal/Distribution/Types/VersionRange/Internal.hs b/Cabal/Distribution/Types/VersionRange/Internal.hs index 129a981e5b9..f8902ac9f54 100644 --- a/Cabal/Distribution/Types/VersionRange/Internal.hs +++ b/Cabal/Distribution/Types/VersionRange/Internal.hs @@ -42,7 +42,6 @@ import Distribution.CabalSpecVersion import Distribution.Parsec import Distribution.Pretty import Distribution.Utils.Generic (unsnoc) -import Text.PrettyPrint ((<+>)) import qualified Distribution.Compat.CharParsing as P import qualified Distribution.Compat.DList as DList diff --git a/Cabal/Distribution/Utils/Generic.hs b/Cabal/Distribution/Utils/Generic.hs index 496fe9b01ee..73b96761f8b 100644 --- a/Cabal/Distribution/Utils/Generic.hs +++ b/Cabal/Distribution/Utils/Generic.hs @@ -90,8 +90,6 @@ import Distribution.Utils.String import Data.Bits ((.&.), (.|.), shiftL) import Data.List ( isInfixOf ) -import Data.Ord - ( comparing ) import qualified Data.ByteString.Lazy as BS import qualified Data.Set as Set diff --git a/Cabal/tests/UnitTests/Distribution/Version.hs b/Cabal/tests/UnitTests/Distribution/Version.hs index 02a5cc51d3e..024ab84012e 100644 --- a/Cabal/tests/UnitTests/Distribution/Version.hs +++ b/Cabal/tests/UnitTests/Distribution/Version.hs @@ -16,7 +16,7 @@ import Distribution.Utils.Generic import Data.Typeable (typeOf) import Math.NumberTheory.Logarithms (intLog2) import Text.PrettyPrint as Disp (text, render, hcat - ,punctuate, int, char, (<+>)) + ,punctuate, int, char) import Test.Tasty import Test.Tasty.QuickCheck import qualified Test.Laws as Laws @@ -24,7 +24,6 @@ import qualified Test.Laws as Laws import Test.QuickCheck.Instances.Cabal () import Data.Maybe (fromJust) -import Data.Function (on) versionTests :: [TestTree] versionTests = diff --git a/Makefile b/Makefile index 189e53d284e..886e8810150 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,10 @@ gen-extra-source-files : gen-extra-source-files-lib gen-extra-source-files-cli gen-extra-source-files-lib : cabal v2-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- $$(pwd)/Cabal/Cabal.cabal +# analyse-imports +analyse-imports : phony + find Cabal/Distribution cabal-install/Distribution -type f -name '*.hs' | xargs cabal v2-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta analyse-imports -- + # github actions github-actions : .github/workflows/artifacts.yml github-actions : .github/workflows/quick-jobs.yml diff --git a/cabal-dev-scripts/cabal-dev-scripts.cabal b/cabal-dev-scripts/cabal-dev-scripts.cabal index 267d41b7955..f73d02879e5 100644 --- a/cabal-dev-scripts/cabal-dev-scripts.cabal +++ b/cabal-dev-scripts/cabal-dev-scripts.cabal @@ -80,3 +80,14 @@ executable gen-cabal-macros , syb ^>=0.7.1 , template-haskell , zinza ^>=0.2 + +executable analyse-imports + default-language: Haskell2010 + main-is: AnalyseImports.hs + hs-source-dirs: src + ghc-options: -Wall + build-depends: + , base + , containers + , regex-applicative + , haskell-lexer ^>=1.1 diff --git a/cabal-dev-scripts/src/AnalyseImports.hs b/cabal-dev-scripts/src/AnalyseImports.hs new file mode 100644 index 00000000000..5c96155527b --- /dev/null +++ b/cabal-dev-scripts/src/AnalyseImports.hs @@ -0,0 +1,106 @@ +{-# LANGUAGE LambdaCase #-} +module Main (main) where + +import Control.Applicative (liftA2, many, (<|>)) +import Control.Monad (void) +import Data.Foldable (for_) +import Data.List (sortBy) +import Data.Maybe (fromMaybe) +import Data.Ord (comparing) +import Language.Haskell.Lexer (PosToken, Token (..), lexerPass0) +import System.Environment (getArgs) +import Text.Regex.Applicative (RE) + +import qualified Data.Map.Strict as Map +import qualified Text.Regex.Applicative as RE + +main :: IO () +main = do + args <- getArgs + + data_ <- traverse processFile args + + putStrLn "Modules" + let modules = sortBy (flip $ comparing snd) $ Map.toList $ Map.fromListWith (+) + [ (mn, 1 :: Int) + | xs <- data_ + , (mn, _) <- xs + ] + + for_ (take 30 modules) $ \(mn, n) -> + putStrLn $ mn ++ " " ++ show n + + putStrLn "" + + putStrLn "Symbols" + let symbols = sortBy (flip $ comparing snd) $ Map.toList $ Map.fromListWith (+) + [ ((mn,sym), 1 :: Int) + | xs <- data_ + , (mn, syms) <- xs + , sym <- syms + ] + + for_ (take 50 symbols) $ \((mn,sym), n) -> + putStrLn $ mn ++ "." ++ sym ++ " " ++ show n + +processFile :: FilePath -> IO [(String, [String])] +processFile fp = do + contents <- readFile fp + let tokens = filter (\(t, _) -> t `notElem` [Whitespace, Comment, Commentstart, NestedComment]) + $ lexerPass0 contents + + return $ fromMaybe [] $ RE.match (somewhere imports) tokens + +imports :: RE PosToken (String, [String]) +imports = (,) + <$ reservedid "import" <*> (conid <|> qconid) <*> msymbols + where + msymbols :: RE PosToken [String] + msymbols =special "(" *> symbols <* special ")" <|> pure [] + + symbols :: RE PosToken [String] + symbols = liftA2 (:) symbol $ many (special "," *> symbol) + + symbol :: RE PosToken String + symbol = varid <|> special "(" *> varsym <* special ")" + + +------------------------------------------------------------------------------- +-- regex-applicative + haskell-lexer +------------------------------------------------------------------------------- + +anything :: RE s () +anything = void $ RE.few RE.anySym + +somewhere :: RE s a -> RE s [a] +somewhere re = anything *> RE.few (re <* anything) + +reservedid :: String -> RE PosToken () +reservedid k = RE.msym $ \case + (Reservedid, (_, k')) | k == k' -> Just () + _ -> Nothing + +special :: String -> RE PosToken () +special k = RE.msym $ \case + (Special, (_, k')) | k == k' -> Just () + _ -> Nothing + +conid :: RE PosToken String +conid = RE.msym $ \case + (Conid, (_, k)) -> Just k + _ -> Nothing + +qconid :: RE PosToken String +qconid = RE.msym $ \case + (Qconid, (_, k)) -> Just k + _ -> Nothing + +varid :: RE PosToken String +varid = RE.msym $ \case + (Varid, (_, k)) -> Just k + _ -> Nothing + +varsym :: RE PosToken String +varsym = RE.msym $ \case + (Varsym, (_, k)) -> Just k + _ -> Nothing diff --git a/cabal-install/Distribution/Client/BuildReports/Storage.hs b/cabal-install/Distribution/Client/BuildReports/Storage.hs index 06f7244fbad..039dd7bdd08 100644 --- a/cabal-install/Distribution/Client/BuildReports/Storage.hs +++ b/cabal-install/Distribution/Client/BuildReports/Storage.hs @@ -24,6 +24,9 @@ module Distribution.Client.BuildReports.Storage ( fromPlanningFailure, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.BuildReports.Anonymous (BuildReport, showBuildReport, newBuildReport) import qualified Distribution.Client.BuildReports.Anonymous as BuildReport @@ -47,12 +50,11 @@ import Distribution.System import Distribution.Compiler ( CompilerId(..), CompilerInfo(..) ) import Distribution.Simple.Utils - ( comparing, equating ) + ( equating ) -import Data.List - ( groupBy, sortBy ) -import Data.Maybe - ( mapMaybe ) +import Data.List.NonEmpty + ( groupBy ) +import qualified Data.List as L import System.FilePath ( (), takeDirectory ) import System.Directory @@ -71,8 +73,8 @@ storeAnonymous reports = sequence_ separate :: [(BuildReport, Maybe Repo)] -> [(Repo, [BuildReport])] separate = map (\rs@((_,repo,_):_) -> (repo, [ r | (r,_,_) <- rs ])) - . map concat - . groupBy (equating (repoName . head)) + . map (concatMap toList) + . L.groupBy (equating (repoName . head)) . sortBy (comparing (repoName . head)) . groupBy (equating repoName) . onlyRemote @@ -115,7 +117,7 @@ storeLocal cinfo templates reports platform = sequence_ platform groupByFileName = map (\grp@((filename,_):_) -> (filename, map snd grp)) - . groupBy (equating fst) + . L.groupBy (equating fst) . sortBy (comparing fst) -- ------------------------------------------------------------ diff --git a/cabal-install/Distribution/Client/BuildReports/Types.hs b/cabal-install/Distribution/Client/BuildReports/Types.hs index df0abeb7a01..dc5b8e2ce1b 100644 --- a/cabal-install/Distribution/Client/BuildReports/Types.hs +++ b/cabal-install/Distribution/Client/BuildReports/Types.hs @@ -26,11 +26,8 @@ import qualified Text.PrettyPrint as Disp import Distribution.Compiler (CompilerId (..)) import Distribution.PackageDescription (FlagAssignment) -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) import Distribution.System (Arch, OS) import Distribution.Types.PackageId (PackageIdentifier) -import Text.PrettyPrint ((<+>)) ------------------------------------------------------------------------------- -- ReportLevel diff --git a/cabal-install/Distribution/Client/BuildReports/Upload.hs b/cabal-install/Distribution/Client/BuildReports/Upload.hs index 9681f90a682..28ca9353882 100644 --- a/cabal-install/Distribution/Client/BuildReports/Upload.hs +++ b/cabal-install/Distribution/Client/BuildReports/Upload.hs @@ -7,6 +7,9 @@ module Distribution.Client.BuildReports.Upload , uploadReports ) where +import Distribution.Client.Compat.Prelude +import Prelude () + {- import Network.Browser ( BrowserAction, request, setAllowRedirects ) @@ -17,14 +20,10 @@ import Network.TCP (HandleStream) -} import Network.URI (URI, uriPath) --parseRelativeReference, relativeTo) -import Control.Monad - ( forM_ ) import System.FilePath.Posix ( () ) import qualified Distribution.Client.BuildReports.Anonymous as BuildReport import Distribution.Client.BuildReports.Anonymous (BuildReport, showBuildReport) -import Distribution.Pretty (prettyShow) -import Distribution.Verbosity (Verbosity) import Distribution.Simple.Utils (die') import Distribution.Client.HttpUtils import Distribution.Client.Setup @@ -35,7 +34,7 @@ type BuildLog = String uploadReports :: Verbosity -> RepoContext -> (String, String) -> URI -> [(BuildReport, Maybe BuildLog)] -> IO () uploadReports verbosity repoCtxt auth uri reports = do - forM_ reports $ \(report, mbBuildLog) -> do + for_ reports $ \(report, mbBuildLog) -> do buildId <- postBuildReport verbosity repoCtxt auth uri report case mbBuildLog of Just buildLog -> putBuildLog verbosity repoCtxt auth buildId buildLog diff --git a/cabal-install/Distribution/Client/Check.hs b/cabal-install/Distribution/Client/Check.hs index 190cf46e507..a8bbdadda03 100644 --- a/cabal-install/Distribution/Client/Check.hs +++ b/cabal-install/Distribution/Client/Check.hs @@ -28,7 +28,6 @@ import Distribution.PackageDescription.Parsec (parseGenericPackageDescription, runParseResult) import Distribution.Parsec (PWarning (..), showPError, showPWarning) import Distribution.Simple.Utils (defaultPackageDesc, die', notice, warn) -import Distribution.Verbosity (Verbosity) import System.IO (hPutStr, stderr) import qualified Data.ByteString as BS diff --git a/cabal-install/Distribution/Client/CmdBench.hs b/cabal-install/Distribution/Client/CmdBench.hs index 41329ef012d..c5056c38121 100644 --- a/cabal-install/Distribution/Client/CmdBench.hs +++ b/cabal-install/Distribution/Client/CmdBench.hs @@ -13,6 +13,9 @@ module Distribution.Client.CmdBench ( selectComponentTarget ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages @@ -24,16 +27,11 @@ import Distribution.Simple.Flag ( fromFlagOrDefault ) import Distribution.Simple.Command ( CommandUI(..), usageAlternatives ) -import Distribution.Pretty - ( prettyShow ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Utils ( wrapText, die' ) -import Control.Monad (when) - - benchCommand :: CommandUI (NixStyleFlags ()) benchCommand = CommandUI { commandName = "v2-bench", diff --git a/cabal-install/Distribution/Client/CmdBuild.hs b/cabal-install/Distribution/Client/CmdBuild.hs index 0b828f05d7e..a830d0e4276 100644 --- a/cabal-install/Distribution/Client/CmdBuild.hs +++ b/cabal-install/Distribution/Client/CmdBuild.hs @@ -26,7 +26,7 @@ import Distribution.Simple.Flag ( Flag(..), toFlag, fromFlag, fromFlagOrDefault import Distribution.Simple.Command ( CommandUI(..), usageAlternatives, option, optionName ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Utils ( wrapText, die' ) diff --git a/cabal-install/Distribution/Client/CmdClean.hs b/cabal-install/Distribution/Client/CmdClean.hs index 7aab28f96ec..956552b3f06 100644 --- a/cabal-install/Distribution/Client/CmdClean.hs +++ b/cabal-install/Distribution/Client/CmdClean.hs @@ -20,12 +20,8 @@ import Distribution.Simple.Command import Distribution.Simple.Utils ( info, die', wrapText, handleDoesNotExist ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) -import Control.Monad - ( mapM_ ) -import Control.Exception - ( throwIO ) import System.Directory ( removeDirectoryRecursive, removeFile , doesDirectoryExist, getDirectoryContents ) @@ -111,5 +107,5 @@ cleanAction CleanFlags{..} extraArgs _ = do removeEnvFiles :: FilePath -> IO () removeEnvFiles dir = - (mapM_ (removeFile . (dir )) . filter ((".ghc.environment" ==) . take 16)) + (traverse_ (removeFile . (dir )) . filter ((".ghc.environment" ==) . take 16)) =<< getDirectoryContents dir diff --git a/cabal-install/Distribution/Client/CmdConfigure.hs b/cabal-install/Distribution/Client/CmdConfigure.hs index 7e2aa01be10..75955d9aea0 100644 --- a/cabal-install/Distribution/Client/CmdConfigure.hs +++ b/cabal-install/Distribution/Client/CmdConfigure.hs @@ -6,8 +6,10 @@ module Distribution.Client.CmdConfigure ( configureAction, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import System.Directory -import Control.Monad import qualified Data.Map as Map import Distribution.Client.ProjectOrchestration diff --git a/cabal-install/Distribution/Client/CmdErrorMessages.hs b/cabal-install/Distribution/Client/CmdErrorMessages.hs index 34d7bfda455..2db501d1f4f 100644 --- a/cabal-install/Distribution/Client/CmdErrorMessages.hs +++ b/cabal-install/Distribution/Client/CmdErrorMessages.hs @@ -22,11 +22,8 @@ import Distribution.Types.LibraryName ( LibraryName(..) ) import Distribution.Solver.Types.OptionalStanza ( OptionalStanza(..) ) -import Distribution.Pretty - ( prettyShow ) import qualified Data.List.NonEmpty as NE -import Data.Function (on) ----------------------- diff --git a/cabal-install/Distribution/Client/CmdExec.hs b/cabal-install/Distribution/Client/CmdExec.hs index f570b2ff69f..1d47222bc9a 100644 --- a/cabal-install/Distribution/Client/CmdExec.hs +++ b/cabal-install/Distribution/Client/CmdExec.hs @@ -83,8 +83,7 @@ import Distribution.Simple.Utils , wrapText ) import Distribution.Verbosity - ( Verbosity - , normal + ( normal ) import Prelude () diff --git a/cabal-install/Distribution/Client/CmdFreeze.hs b/cabal-install/Distribution/Client/CmdFreeze.hs index 6f1f67866ed..ed472818258 100644 --- a/cabal-install/Distribution/Client/CmdFreeze.hs +++ b/cabal-install/Distribution/Client/CmdFreeze.hs @@ -7,6 +7,9 @@ module Distribution.Client.CmdFreeze ( freezeAction, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.NixStyleOptions ( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags ) import Distribution.Client.ProjectOrchestration @@ -44,8 +47,6 @@ import Distribution.Verbosity ( normal ) import qualified Data.Map as Map -import Data.Map (Map) -import Control.Monad (unless) import Distribution.Simple.Command ( CommandUI(..), usageAlternatives ) diff --git a/cabal-install/Distribution/Client/CmdHaddock.hs b/cabal-install/Distribution/Client/CmdHaddock.hs index 3c932ba0ac4..f965204f175 100644 --- a/cabal-install/Distribution/Client/CmdHaddock.hs +++ b/cabal-install/Distribution/Client/CmdHaddock.hs @@ -13,6 +13,9 @@ module Distribution.Client.CmdHaddock ( selectComponentTarget ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages @@ -25,13 +28,10 @@ import Distribution.Simple.Setup import Distribution.Simple.Command ( CommandUI(..), usageAlternatives ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Utils ( wrapText, die' ) -import Control.Monad (when) - - haddockCommand :: CommandUI (NixStyleFlags ()) haddockCommand = CommandUI { commandName = "v2-haddock", diff --git a/cabal-install/Distribution/Client/CmdInstall.hs b/cabal-install/Distribution/Client/CmdInstall.hs index 2a09baa26c1..022ef610fdd 100644 --- a/cabal-install/Distribution/Client/CmdInstall.hs +++ b/cabal-install/Distribution/Client/CmdInstall.hs @@ -120,27 +120,17 @@ import Distribution.Types.UnitId import Distribution.Types.UnqualComponentName ( UnqualComponentName, unUnqualComponentName ) import Distribution.Verbosity - ( Verbosity, normal, lessVerbose ) + ( normal, lessVerbose ) import Distribution.Simple.Utils ( wrapText, die', notice, warn , withTempDirectory, createDirectoryIfMissingVerbose , ordNub ) import Distribution.Utils.Generic ( safeHead, writeFileAtomic ) -import Distribution.Parsec - ( simpleParsec ) -import Distribution.Pretty - ( prettyShow ) - -import Control.Exception - ( catch ) -import Control.Monad - ( mapM, forM_ ) + import qualified Data.ByteString.Lazy.Char8 as BS -import Data.Either - ( partitionEithers ) import Data.Ord - ( comparing, Down(..) ) + ( Down(..) ) import qualified Data.Map as Map import Distribution.Utils.NubList ( fromNubList ) @@ -263,7 +253,7 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe withoutProject :: ProjectConfig -> IO ([PackageSpecifier pkg], [URI], [TargetSelector], ProjectConfig) withoutProject globalConfig = do - tss <- mapM (parseWithoutProjectTargetSelector verbosity) targetStrings' + tss <- traverse (parseWithoutProjectTargetSelector verbosity) targetStrings' cabalDir <- getCabalDir let @@ -478,7 +468,7 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity pkgDb targetSelectors loca createDirectoryIfMissing True (distSdistDirectory localDistDirLayout) - unless (Map.null targets) $ forM_ (localPackages localBaseCtx) $ \lpkg -> case lpkg of + unless (Map.null targets) $ for_ (localPackages localBaseCtx) $ \lpkg -> case lpkg of SpecificSourcePackage pkg -> packageToSdist verbosity (distProjectRootDirectory localDistDirLayout) TarGzArchive (distSdistFile localDistDirLayout (packageId pkg)) pkg diff --git a/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs b/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs index a181dd475cb..acfe39a6529 100644 --- a/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs +++ b/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs @@ -16,8 +16,6 @@ import Distribution.Simple.Command ( ShowOrParseArgs(..), OptionField(..), option, reqArg ) import Distribution.Simple.Setup ( Flag(..), trueArg, flagToList, toFlag ) -import Distribution.Parsec (Parsec (..), CabalParsing) -import Distribution.Pretty (prettyShow) import Distribution.Client.Types.InstallMethod ( InstallMethod (..) ) diff --git a/cabal-install/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs b/cabal-install/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs index 137ad2ee7fd..0127aea0f3c 100644 --- a/cabal-install/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs +++ b/cabal-install/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs @@ -15,11 +15,9 @@ import Distribution.Client.TargetSelector import Distribution.Client.Types import Distribution.Compat.CharParsing (char, optional) import Distribution.Package -import Distribution.Parsec import Distribution.Simple.LocalBuildInfo (ComponentName (CExeName)) import Distribution.Simple.Utils (die') import Distribution.Solver.Types.PackageConstraint (PackageProperty (..)) -import Distribution.Verbosity (Verbosity) import Distribution.Version data WithoutProjectTargetSelector @@ -36,7 +34,7 @@ parseWithoutProjectTargetSelector verbosity input = Just uri -> return (WoURI uri) Nothing -> die' verbosity $ "Invalid package ID: " ++ input ++ "\n" ++ err where - parser :: ParsecParser WithoutProjectTargetSelector + parser :: CabalParsing m => m WithoutProjectTargetSelector parser = do pid <- parsec cn <- optional (char ':' *> parsec) diff --git a/cabal-install/Distribution/Client/CmdLegacy.hs b/cabal-install/Distribution/Client/CmdLegacy.hs index 532ff47a540..a8b0bb0b119 100644 --- a/cabal-install/Distribution/Client/CmdLegacy.hs +++ b/cabal-install/Distribution/Client/CmdLegacy.hs @@ -17,10 +17,10 @@ import Distribution.Simple.Command import Distribution.Simple.Utils ( wrapText ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Control.Exception - ( SomeException(..), try ) + ( try ) import qualified Data.Text as T -- Tweaked versions of code from Main. diff --git a/cabal-install/Distribution/Client/CmdRepl.hs b/cabal-install/Distribution/Client/CmdRepl.hs index c4f649d2e7e..b9c8511ad0b 100644 --- a/cabal-install/Distribution/Client/CmdRepl.hs +++ b/cabal-install/Distribution/Client/CmdRepl.hs @@ -56,9 +56,7 @@ import Distribution.Package ( Package(..), packageName, UnitId, installedUnitId ) import Distribution.PackageDescription.PrettyPrint import Distribution.Parsec - ( Parsec(..), parsecCommaList ) -import Distribution.Pretty - ( prettyShow ) + ( parsecCommaList ) import Distribution.ReadE ( ReadE, parsecToReadE ) import qualified Distribution.SPDX.License as SPDX @@ -87,7 +85,7 @@ import Distribution.Types.VersionRange import Distribution.Utils.Generic ( safeHead ) import Distribution.Verbosity - ( Verbosity, normal, lessVerbose ) + ( normal, lessVerbose ) import Distribution.Simple.Utils ( wrapText, die', debugNoWrap, ordNub, createTempDirectory, handleDoesNotExist ) import Language.Haskell.Extension diff --git a/cabal-install/Distribution/Client/CmdRun.hs b/cabal-install/Distribution/Client/CmdRun.hs index b2d58f2a755..ddfb9e8c584 100644 --- a/cabal-install/Distribution/Client/CmdRun.hs +++ b/cabal-install/Distribution/Client/CmdRun.hs @@ -37,11 +37,9 @@ import Distribution.Simple.Command ( CommandUI(..), usageAlternatives ) import Distribution.Types.ComponentName ( showComponentName ) -import Distribution.Pretty - ( prettyShow ) import Distribution.CabalSpecVersion (CabalSpecVersion (..), cabalSpecLatest) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Utils ( wrapText, warn, die', ordNub, info , createTempDirectory, handleDoesNotExist ) diff --git a/cabal-install/Distribution/Client/CmdSdist.hs b/cabal-install/Distribution/Client/CmdSdist.hs index 01fe6f9cc38..ec268a55533 100644 --- a/cabal-install/Distribution/Client/CmdSdist.hs +++ b/cabal-install/Distribution/Client/CmdSdist.hs @@ -39,8 +39,6 @@ import Distribution.Package ( Package(packageId) ) import Distribution.PackageDescription.Configuration ( flattenPackageDescription ) -import Distribution.Pretty - ( prettyShow ) import Distribution.ReadE ( succeedReadE ) import Distribution.Simple.Command @@ -60,7 +58,7 @@ import Distribution.Types.ComponentName import Distribution.Types.PackageName ( PackageName, unPackageName ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar.Entry as Tar @@ -73,8 +71,6 @@ import Control.Monad.Writer.Lazy ( WriterT, tell, execWriterT ) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as BSL -import Data.Either - ( partitionEithers ) import qualified Data.Set as Set import System.Directory ( getCurrentDirectory diff --git a/cabal-install/Distribution/Client/CmdTest.hs b/cabal-install/Distribution/Client/CmdTest.hs index ea467939736..b2510500f2b 100644 --- a/cabal-install/Distribution/Client/CmdTest.hs +++ b/cabal-install/Distribution/Client/CmdTest.hs @@ -13,6 +13,9 @@ module Distribution.Client.CmdTest ( selectComponentTarget ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages @@ -26,14 +29,11 @@ import Distribution.Simple.Command ( CommandUI(..), usageAlternatives ) import Distribution.Simple.Flag ( Flag(..) ) -import Distribution.Pretty - ( prettyShow ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Utils ( notice, wrapText, die' ) -import Control.Monad (when) import qualified System.Exit (exitSuccess) diff --git a/cabal-install/Distribution/Client/CmdUpdate.hs b/cabal-install/Distribution/Client/CmdUpdate.hs index d4b3ff7dc71..b6646874532 100644 --- a/cabal-install/Distribution/Client/CmdUpdate.hs +++ b/cabal-install/Distribution/Client/CmdUpdate.hs @@ -44,20 +44,17 @@ import Distribution.Simple.Flag import Distribution.Simple.Utils ( die', notice, wrapText, writeFileAtomic, noticeNoWrap ) import Distribution.Verbosity - ( Verbosity, normal, lessVerbose ) + ( normal, lessVerbose ) import Distribution.Client.IndexUtils.Timestamp import Distribution.Client.IndexUtils.IndexState import Distribution.Client.IndexUtils ( updateRepoIndexCache, Index(..), writeIndexTimestamp , currentIndexTimestamp, indexBaseName ) -import Distribution.Pretty (Pretty (..), prettyShow) -import Distribution.Parsec (Parsec (..), simpleParsec) -import Data.Maybe (fromJust) +import qualified Data.Maybe as Unsafe (fromJust) import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp -import Control.Monad (mapM, mapM_) import qualified Data.ByteString.Lazy as BS import Distribution.Client.GZipUtils (maybeDecompress) import System.FilePath ((<.>), dropExtension) @@ -136,7 +133,7 @@ updateAction flags@NixStyleFlags {..} extraArgs globalFlags = do Just r -> return r Nothing -> die' verbosity $ "'v2-update' unable to parse repo: \"" ++ s ++ "\"" - updateRepoRequests <- mapM parseArg extraArgs + updateRepoRequests <- traverse parseArg extraArgs unless (null updateRepoRequests) $ do let remoteRepoNames = map repoName repos @@ -154,7 +151,7 @@ updateAction flags@NixStyleFlags {..} extraArgs globalFlags = do -- repositories to HEAD. [] -> map (,IndexStateHead) repos updateRequests -> let repoMap = [(repoName r, r) | r <- repos] - lookup' k = fromJust (lookup k repoMap) + lookup' k = Unsafe.fromJust (lookup k repoMap) in [ (lookup' name, state) | (UpdateRequest name state) <- updateRequests ] @@ -168,9 +165,9 @@ updateAction flags@NixStyleFlags {..} extraArgs globalFlags = do : map (("- " ++) . unRepoName . repoName . fst) reposToUpdate jobCtrl <- newParallelJobControl (length reposToUpdate) - mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) + traverse_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) reposToUpdate - mapM_ (\_ -> collectJob jobCtrl) reposToUpdate + traverse_ (\_ -> collectJob jobCtrl) reposToUpdate where verbosity = fromFlagOrDefault normal (configVerbosity configFlags) diff --git a/cabal-install/Distribution/Client/Compat/ExecutablePath.hs b/cabal-install/Distribution/Client/Compat/ExecutablePath.hs index 79ef241627d..8a799b6de7d 100644 --- a/cabal-install/Distribution/Client/Compat/ExecutablePath.hs +++ b/cabal-install/Distribution/Client/Compat/ExecutablePath.hs @@ -7,6 +7,8 @@ module Distribution.Client.Compat.ExecutablePath ( getExecutablePath ) where +import Prelude + -- The imports are purposely kept completely disjoint to prevent edits -- to one OS implementation from breaking another. diff --git a/cabal-install/Distribution/Client/Compat/FilePerms.hs b/cabal-install/Distribution/Client/Compat/FilePerms.hs index 2f547fea60c..006f892ea54 100644 --- a/cabal-install/Distribution/Client/Compat/FilePerms.hs +++ b/cabal-install/Distribution/Client/Compat/FilePerms.hs @@ -6,6 +6,8 @@ module Distribution.Client.Compat.FilePerms ( setFileHidden, ) where +import Prelude (FilePath, IO, return, ($)) + #ifndef mingw32_HOST_OS import System.Posix.Types ( FileMode ) diff --git a/cabal-install/Distribution/Client/Compat/Orphans.hs b/cabal-install/Distribution/Client/Compat/Orphans.hs index 91faa0c7a10..aef25787f45 100644 --- a/cabal-install/Distribution/Client/Compat/Orphans.hs +++ b/cabal-install/Distribution/Client/Compat/Orphans.hs @@ -7,6 +7,7 @@ import Distribution.Compat.Binary (Binary (..)) import Distribution.Compat.Typeable (typeRep) import Distribution.Utils.Structured (Structure (Nominal), Structured (..)) import Network.URI (URI (..), URIAuth (..)) +import Prelude (error, return) ------------------------------------------------------------------------------- -- network-uri @@ -34,7 +35,7 @@ instance Binary URIAuth where --Added in 46aa019ec85e313e257d122a3549cce01996c566 instance Binary SomeException where put _ = return () - get = fail "cannot serialise exceptions" + get = error "cannot serialise exceptions" instance Structured SomeException where structure p = Nominal (typeRep p) 0 "SomeException" [] diff --git a/cabal-install/Distribution/Client/Compat/Prelude.hs b/cabal-install/Distribution/Client/Compat/Prelude.hs index 2846f888ff9..38978ef8d3f 100644 --- a/cabal-install/Distribution/Client/Compat/Prelude.hs +++ b/cabal-install/Distribution/Client/Compat/Prelude.hs @@ -12,7 +12,13 @@ -- module Distribution.Client.Compat.Prelude ( module Distribution.Compat.Prelude.Internal + , module X ) where -import Distribution.Compat.Prelude.Internal import Distribution.Client.Compat.Orphans () +import Distribution.Compat.Prelude.Internal +import Prelude () + +import Distribution.Parsec as X (CabalParsing, Parsec (..), eitherParsec, explicitEitherParsec, simpleParsec) +import Distribution.Pretty as X (Pretty (..), prettyShow) +import Distribution.Verbosity as X (Verbosity) diff --git a/cabal-install/Distribution/Client/Compat/Process.hs b/cabal-install/Distribution/Client/Compat/Process.hs index 8b71b173712..c8039c3e038 100644 --- a/cabal-install/Distribution/Client/Compat/Process.hs +++ b/cabal-install/Distribution/Client/Compat/Process.hs @@ -16,6 +16,8 @@ module Distribution.Client.Compat.Process ( readProcessWithExitCode ) where +import Prelude (FilePath, IO, String, return, (||)) + import Control.Exception (catch, throw) import System.Exit (ExitCode (ExitFailure)) import System.IO.Error (isDoesNotExistError, isPermissionError) diff --git a/cabal-install/Distribution/Client/Compat/Semaphore.hs b/cabal-install/Distribution/Client/Compat/Semaphore.hs index e4d04c0db79..8ea6c3afb3a 100644 --- a/cabal-install/Distribution/Client/Compat/Semaphore.hs +++ b/cabal-install/Distribution/Client/Compat/Semaphore.hs @@ -7,6 +7,8 @@ module Distribution.Client.Compat.Semaphore , signalQSem ) where +import Prelude (IO, return, Eq (..), Int, Bool (..), ($), ($!), Num (..), flip) + import Control.Concurrent.STM (TVar, atomically, newTVar, readTVar, retry, writeTVar) import Control.Exception (mask_, onException) diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index 152583fba4b..e1c63a8c354 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -117,19 +117,16 @@ import Distribution.Client.Utils import Distribution.Compiler ( CompilerFlavor(..), defaultCompilerFlavor ) import Distribution.Verbosity - ( Verbosity, normal ) + ( normal ) import qualified Distribution.Compat.CharParsing as P import Distribution.Client.ProjectFlags (ProjectFlags (..)) import Distribution.Solver.Types.ConstraintSource -import Data.List - ( partition ) import qualified Distribution.Deprecated.ReadP as Parse ( (<++), option ) import qualified Text.PrettyPrint as Disp ( render, text, empty ) -import Distribution.Parsec (parsec, simpleParsec, parsecOptCommaList) -import Distribution.Pretty (pretty, prettyShow) +import Distribution.Parsec (parsecOptCommaList) import Text.PrettyPrint ( ($+$) ) import Text.PrettyPrint.HughesPJ @@ -144,11 +141,7 @@ import System.IO.Error ( isDoesNotExistError ) import Distribution.Compat.Environment ( getEnvironment, lookupEnv ) -import Distribution.Compat.Exception - ( catchIO ) import qualified Data.Map as M -import Data.Function - ( on ) -- -- * Configuration saved in the config file diff --git a/cabal-install/Distribution/Client/Configure.hs b/cabal-install/Distribution/Client/Configure.hs index d548219fd55..be6f5e3986d 100644 --- a/cabal-install/Distribution/Client/Configure.hs +++ b/cabal-install/Distribution/Client/Configure.hs @@ -26,7 +26,6 @@ import Prelude () import Distribution.Client.Compat.Prelude import Distribution.Utils.Generic (safeHead) -import Distribution.Pretty (prettyShow) import Distribution.Client.Dependency import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.SolverInstallPlan (SolverInstallPlan) @@ -81,11 +80,7 @@ import Distribution.Simple.Utils as Utils , defaultPackageDesc ) import Distribution.System ( Platform ) -import Distribution.Verbosity as Verbosity - ( Verbosity ) -import Data.Foldable - ( forM_ ) import System.FilePath ( () ) -- | Choose the Cabal version such that the setup scripts compiled against this @@ -273,10 +268,10 @@ checkConfigExFlags :: Package pkg -> ConfigExFlags -> IO () checkConfigExFlags verbosity installedPkgIndex sourcePkgIndex flags = do - forM_ (safeHead unknownConstraints) $ \h -> + for_ (safeHead unknownConstraints) $ \h -> warn verbosity $ "Constraint refers to an unknown package: " ++ showConstraint h - forM_ (safeHead unknownPreferences) $ \h -> + for_ (safeHead unknownPreferences) $ \h -> warn verbosity $ "Preference refers to an unknown package: " ++ prettyShow h where diff --git a/cabal-install/Distribution/Client/Dependency.hs b/cabal-install/Distribution/Client/Dependency.hs index e7efaab9bd0..6da12f01cb7 100644 --- a/cabal-install/Distribution/Client/Dependency.hs +++ b/cabal-install/Distribution/Client/Dependency.hs @@ -64,6 +64,9 @@ module Distribution.Client.Dependency ( addSetupCabalMaxVersionConstraint, ) where +import Distribution.Client.Compat.Prelude +import qualified Prelude as Unsafe (head) + import Distribution.Solver.Modular ( modularResolver, SolverConfig(..), PruneAfterFirstSuccess(..) ) import Distribution.Simple.PackageIndex (InstalledPackageIndex) @@ -96,13 +99,10 @@ import Distribution.System ( Platform ) import Distribution.Client.Utils ( duplicatesBy, mergeBy, MergeResult(..) ) -import Distribution.Simple.Utils - ( comparing ) import Distribution.Simple.Setup ( asBool ) -import Distribution.Pretty (prettyShow) import Distribution.Verbosity - ( normal, Verbosity ) + ( normal ) import Distribution.Version import qualified Distribution.Compat.Graph as Graph @@ -127,12 +127,9 @@ import Distribution.Solver.Types.SourcePackage import Distribution.Solver.Types.Variable import Data.List - ( foldl', sort, sortBy, nubBy, maximumBy, intercalate, nub ) -import Data.Function (on) -import Data.Maybe (fromMaybe, mapMaybe) + ( maximumBy ) import qualified Data.Map as Map import qualified Data.Set as Set -import Data.Set (Set) import Control.Exception ( assert ) @@ -847,7 +844,7 @@ planPackagesProblems platform cinfo pkgs = | Configured pkg <- pkgs , let packageProblems = configuredPackageProblems platform cinfo pkg , not (null packageProblems) ] - ++ [ DuplicatePackageSolverId (Graph.nodeKey (head dups)) dups + ++ [ DuplicatePackageSolverId (Graph.nodeKey (Unsafe.head dups)) dups | dups <- duplicatesBy (comparing Graph.nodeKey) pkgs ] data PackageProblem = DuplicateFlag PD.FlagName @@ -1029,11 +1026,6 @@ collectEithers = collect . partitionEithers where collect ([], xs) = Right xs collect (errs,_) = Left errs - partitionEithers :: [Either a b] -> ([a],[b]) - partitionEithers = foldr (either left right) ([],[]) - where - left a (l, r) = (a:l, r) - right a (l, r) = (l, a:r) -- | Errors for 'resolveWithoutDependencies'. -- diff --git a/cabal-install/Distribution/Client/Dependency/Types.hs b/cabal-install/Distribution/Client/Dependency/Types.hs index 0f19012868b..9a8a3caa5c5 100644 --- a/cabal-install/Distribution/Client/Dependency/Types.hs +++ b/cabal-install/Distribution/Client/Dependency/Types.hs @@ -8,8 +8,6 @@ module Distribution.Client.Dependency.Types ( import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) import Text.PrettyPrint (text) import qualified Distribution.Compat.CharParsing as P diff --git a/cabal-install/Distribution/Client/DistDirLayout.hs b/cabal-install/Distribution/Client/DistDirLayout.hs index 3195ae43d65..15f3852268a 100644 --- a/cabal-install/Distribution/Client/DistDirLayout.hs +++ b/cabal-install/Distribution/Client/DistDirLayout.hs @@ -22,7 +22,9 @@ module Distribution.Client.DistDirLayout ( defaultCabalDirLayout ) where -import Data.Maybe (fromMaybe) +import Distribution.Client.Compat.Prelude +import Prelude () + import System.FilePath import Distribution.Package @@ -30,8 +32,6 @@ import Distribution.Package import Distribution.Compiler import Distribution.Simple.Compiler ( PackageDB(..), PackageDBStack, OptimisationLevel(..) ) -import Distribution.Pretty - ( prettyShow ) import Distribution.Types.ComponentName import Distribution.Types.LibraryName import Distribution.System diff --git a/cabal-install/Distribution/Client/Exec.hs b/cabal-install/Distribution/Client/Exec.hs index 8a21ac4cf04..86d0a6bfc1b 100644 --- a/cabal-install/Distribution/Client/Exec.hs +++ b/cabal-install/Distribution/Client/Exec.hs @@ -21,7 +21,6 @@ import Distribution.Simple.Program.Types ( simpleProgram, ConfiguredProgram(..) import Distribution.Simple.Utils (die') import Distribution.System (Platform(..)) -import Distribution.Verbosity (Verbosity) -- | Execute the given command in the package's environment. -- diff --git a/cabal-install/Distribution/Client/Fetch.hs b/cabal-install/Distribution/Client/Fetch.hs index d8401c3f118..d2f3bc94aa4 100644 --- a/cabal-install/Distribution/Client/Fetch.hs +++ b/cabal-install/Distribution/Client/Fetch.hs @@ -14,6 +14,9 @@ module Distribution.Client.Fetch ( fetch, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.Types import Distribution.Client.Targets import Distribution.Client.FetchUtils hiding (fetchPackage) @@ -44,13 +47,6 @@ import Distribution.Simple.Utils ( die', notice, debug ) import Distribution.System ( Platform ) -import Distribution.Pretty - ( prettyShow ) -import Distribution.Verbosity - ( Verbosity ) - -import Control.Monad - ( filterM ) -- ------------------------------------------------------------ -- * The fetch command @@ -84,7 +80,7 @@ fetch verbosity _ _ _ _ _ _ _ [] = fetch verbosity packageDBs repoCtxt comp platform progdb globalFlags fetchFlags userTargets = do - mapM_ (checkTarget verbosity) userTargets + traverse_ (checkTarget verbosity) userTargets installedPkgIndex <- getInstalledPackages verbosity comp packageDBs progdb sourcePkgDb <- getSourcePackages verbosity repoCtxt @@ -112,7 +108,7 @@ fetch verbosity packageDBs repoCtxt comp platform progdb "The following packages would be fetched:" : map (prettyShow . packageId) pkgs' - else mapM_ (fetchPackage verbosity repoCtxt . packageSource) pkgs' + else traverse_ (fetchPackage verbosity repoCtxt . packageSource) pkgs' where dryRun = fromFlag (fetchDryRun fetchFlags) diff --git a/cabal-install/Distribution/Client/FetchUtils.hs b/cabal-install/Distribution/Client/FetchUtils.hs index 8f010983e6a..d857c53d1e5 100644 --- a/cabal-install/Distribution/Client/FetchUtils.hs +++ b/cabal-install/Distribution/Client/FetchUtils.hs @@ -32,6 +32,9 @@ module Distribution.Client.FetchUtils ( downloadIndex, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.Types import Distribution.Client.HttpUtils ( downloadURI, isOldHackageURI, DownloadResult(..) @@ -41,19 +44,14 @@ import Distribution.Package ( PackageId, packageName, packageVersion ) import Distribution.Simple.Utils ( notice, info, debug, die' ) -import Distribution.Pretty - ( prettyShow ) import Distribution.Verbosity - ( Verbosity, verboseUnmarkOutput ) + ( verboseUnmarkOutput ) import Distribution.Client.GlobalFlags ( RepoContext(..) ) import Distribution.Client.Utils ( ProgressPhase(..), progressMessage ) -import Data.Maybe -import Data.Map (Map) import qualified Data.Map as Map -import Control.Monad import Control.Exception import Control.Concurrent.Async import Control.Concurrent.MVar @@ -237,13 +235,15 @@ asyncFetchPackages :: Verbosity asyncFetchPackages verbosity repoCtxt pkglocs body = do --TODO: [nice to have] use parallel downloads? - asyncDownloadVars <- sequence [ do v <- newEmptyMVar - return (pkgloc, v) - | pkgloc <- pkglocs ] + asyncDownloadVars <- sequenceA + [ do v <- newEmptyMVar + return (pkgloc, v) + | pkgloc <- pkglocs + ] let fetchPackages :: IO () fetchPackages = - forM_ asyncDownloadVars $ \(pkgloc, var) -> do + for_ asyncDownloadVars $ \(pkgloc, var) -> do -- Suppress marking here, because 'withAsync' means -- that we get nondeterministic interleaving result <- try $ fetchPackage (verboseUnmarkOutput verbosity) diff --git a/cabal-install/Distribution/Client/FileMonitor.hs b/cabal-install/Distribution/Client/FileMonitor.hs index 0606f64a21b..b93fdd91dde 100644 --- a/cabal-install/Distribution/Client/FileMonitor.hs +++ b/cabal-install/Distribution/Client/FileMonitor.hs @@ -652,7 +652,7 @@ probeMonitorStateGlobRel kindfile kinddir root dirName . filter (matchGlob glob) =<< liftIO (getDirectoryContents (root dirName)) - children' <- mapM probeMergeResult $ + children' <- traverse probeMergeResult $ mergeBy (\(path1,_) path2 -> compare path1 path2) children (sort matches) @@ -717,14 +717,14 @@ probeMonitorStateGlobRel _ _ root dirName matches <- return . filter (matchGlob glob) =<< liftIO (getDirectoryContents (root dirName)) - mapM_ probeMergeResult $ + traverse_ probeMergeResult $ mergeBy (\(path1,_) path2 -> compare path1 path2) children (sort matches) return mtime' -- Check that none of the children have changed - forM_ children $ \(file, status) -> + for_ children $ \(file, status) -> probeMonitorStateFileStatus root (dirName file) status @@ -928,7 +928,7 @@ buildMonitorStateGlobRel mstartTime hashcache kindfile kinddir root subdirs <- filterM (\subdir -> doesDirectoryExist (absdir subdir)) $ filter (matchGlob glob) dirEntries subdirStates <- - forM (sort subdirs) $ \subdir -> do + for (sort subdirs) $ \subdir -> do fstate <- buildMonitorStateGlobRel mstartTime hashcache kindfile kinddir root (dir subdir) globPath' @@ -938,7 +938,7 @@ buildMonitorStateGlobRel mstartTime hashcache kindfile kinddir root GlobFile glob -> do let files = filter (matchGlob glob) dirEntries filesStates <- - forM (sort files) $ \file -> do + for (sort files) $ \file -> do fstate <- buildMonitorStateFile mstartTime hashcache kindfile kinddir root (dir file) diff --git a/cabal-install/Distribution/Client/Freeze.hs b/cabal-install/Distribution/Client/Freeze.hs index 8a8e68e0706..6b909af5165 100644 --- a/cabal-install/Distribution/Client/Freeze.hs +++ b/cabal-install/Distribution/Client/Freeze.hs @@ -53,10 +53,6 @@ import Distribution.Simple.Utils ( die', notice, debug, writeFileAtomic ) import Distribution.System ( Platform ) -import Distribution.Pretty - ( prettyShow ) -import Distribution.Verbosity - ( Verbosity ) import qualified Data.ByteString.Lazy.Char8 as BS.Char8 import Distribution.Version diff --git a/cabal-install/Distribution/Client/GenBounds.hs b/cabal-install/Distribution/Client/GenBounds.hs index c77fc483755..eccfd021f8b 100644 --- a/cabal-install/Distribution/Client/GenBounds.hs +++ b/cabal-install/Distribution/Client/GenBounds.hs @@ -44,10 +44,6 @@ import Distribution.Simple.Utils ( tryFindPackageDesc ) import Distribution.System ( Platform ) -import Distribution.Pretty - ( prettyShow ) -import Distribution.Verbosity - ( Verbosity ) import Distribution.Version ( Version, alterVersion , LowerBound(..), UpperBound(..), VersionRange, asVersionIntervals diff --git a/cabal-install/Distribution/Client/Get.hs b/cabal-install/Distribution/Client/Get.hs index 26099e2c397..62052806a49 100644 --- a/cabal-install/Distribution/Client/Get.hs +++ b/cabal-install/Distribution/Client/Get.hs @@ -24,7 +24,6 @@ module Distribution.Client.Get ( import Prelude () import Distribution.Client.Compat.Prelude hiding (get) -import Data.Ord (comparing) import Distribution.Compat.Directory ( listDirectory ) import Distribution.Package @@ -33,9 +32,6 @@ import Distribution.Simple.Setup ( Flag(..), fromFlag, fromFlagOrDefault, flagToMaybe ) import Distribution.Simple.Utils ( notice, die', info, writeFileAtomic ) -import Distribution.Verbosity - ( Verbosity ) -import Distribution.Pretty (prettyShow) import qualified Distribution.PackageDescription as PD import Distribution.Simple.Program ( programName ) @@ -54,15 +50,9 @@ import Distribution.Client.IndexUtils ( getSourcePackagesAtIndexState, TotalIndexState, ActiveRepos ) import Distribution.Solver.Types.SourcePackage -import Control.Exception - ( Exception(..), catch, throwIO ) -import Control.Monad - ( mapM, forM_, mapM_ ) import qualified Data.Map as Map import System.Directory ( createDirectoryIfMissing, doesDirectoryExist, doesFileExist ) -import System.Exit - ( ExitCode(..) ) import System.FilePath ( (), (<.>), addTrailingPathSeparator ) @@ -83,7 +73,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do _ -> True unless useSourceRepo $ - mapM_ (checkTarget verbosity) userTargets + traverse_ (checkTarget verbosity) userTargets let idxState :: Maybe TotalIndexState idxState = flagToMaybe $ getIndexState getFlags @@ -128,7 +118,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do unpack :: [UnresolvedSourcePackage] -> IO () unpack pkgs = do - forM_ pkgs $ \pkg -> do + for_ pkgs $ \pkg -> do location <- fetchPackage verbosity repoCtxt (packageSource pkg) let pkgid = packageId pkg descOverride | usePristine = Nothing @@ -263,7 +253,7 @@ clonePackagesFromSourceRepo verbosity destDirPrefix preferredRepoKind pkgrepos = do -- Do a bunch of checks and collect the required info - pkgrepos' <- mapM preCloneChecks pkgrepos + pkgrepos' <- traverse preCloneChecks pkgrepos -- Configure the VCS drivers for all the repository types we may need vcss <- configureVCSs verbosity $ diff --git a/cabal-install/Distribution/Client/Glob.hs b/cabal-install/Distribution/Client/Glob.hs index a6f722fcdaf..5d3d501fbdb 100644 --- a/cabal-install/Distribution/Client/Glob.hs +++ b/cabal-install/Distribution/Client/Glob.hs @@ -22,9 +22,6 @@ import Data.List (stripPrefix) import System.Directory import System.FilePath -import Distribution.Parsec (CabalParsing, Parsec (..)) -import Distribution.Pretty (Pretty (..)) - import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp diff --git a/cabal-install/Distribution/Client/GlobalFlags.hs b/cabal-install/Distribution/Client/GlobalFlags.hs index c011dc4e149..4c050690f47 100644 --- a/cabal-install/Distribution/Client/GlobalFlags.hs +++ b/cabal-install/Distribution/Client/GlobalFlags.hs @@ -24,8 +24,6 @@ import Distribution.Utils.NubList ( NubList, fromNubList ) import Distribution.Client.HttpUtils ( HttpTransport, configureTransport ) -import Distribution.Verbosity - ( Verbosity ) import Distribution.Simple.Utils ( info, warn ) @@ -34,8 +32,6 @@ import Distribution.Client.IndexUtils.ActiveRepos import Control.Concurrent ( MVar, newMVar, modifyMVar ) -import Control.Exception - ( throwIO ) import System.FilePath ( () ) import Network.URI diff --git a/cabal-install/Distribution/Client/Haddock.hs b/cabal-install/Distribution/Client/Haddock.hs index 30a9c600398..01b812678df 100644 --- a/cabal-install/Distribution/Client/Haddock.hs +++ b/cabal-install/Distribution/Client/Haddock.hs @@ -16,8 +16,10 @@ module Distribution.Client.Haddock ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Data.List (maximumBy) -import Data.Foldable (forM_) import System.Directory (createDirectoryIfMissing, renameFile) import System.FilePath ((), splitFileName) import Distribution.Package @@ -26,11 +28,10 @@ import Distribution.Simple.Haddock (haddockPackagePaths) import Distribution.Simple.Program (haddockProgram, ProgramDb , runProgram, requireProgramVersion) import Distribution.Version (mkVersion, orLaterVersion) -import Distribution.Verbosity (Verbosity) import Distribution.Simple.PackageIndex ( InstalledPackageIndex, allPackagesByName ) import Distribution.Simple.Utils - ( comparing, debug, installDirectoryContents, withTempDirectory ) + ( debug, installDirectoryContents, withTempDirectory ) import Distribution.InstalledPackageInfo as InstalledPackageInfo ( InstalledPackageInfo(exposed) ) @@ -41,7 +42,7 @@ regenerateHaddockIndex :: Verbosity regenerateHaddockIndex verbosity pkgs progdb index = do (paths, warns) <- haddockPackagePaths pkgs' Nothing let paths' = [ (interface, html) | (interface, Just html, _) <- paths] - forM_ warns (debug verbosity) + for_ warns (debug verbosity) (confHaddock, _, _) <- requireProgramVersion verbosity haddockProgram diff --git a/cabal-install/Distribution/Client/HashValue.hs b/cabal-install/Distribution/Client/HashValue.hs index 54b8aee9e61..d41c70bf480 100644 --- a/cabal-install/Distribution/Client/HashValue.hs +++ b/cabal-install/Distribution/Client/HashValue.hs @@ -19,7 +19,6 @@ import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as LBS -import Control.Exception (evaluate) import System.IO (IOMode (..), withBinaryFile) ----------------------------------------------- diff --git a/cabal-install/Distribution/Client/HttpUtils.hs b/cabal-install/Distribution/Client/HttpUtils.hs index 79b36f2fcd2..9b8a8ecb844 100644 --- a/cabal-install/Distribution/Client/HttpUtils.hs +++ b/cabal-install/Distribution/Client/HttpUtils.hs @@ -28,14 +28,6 @@ import Network.Browser ( browse, setOutHandler, setErrHandler, setProxy , setAuthorityGen, request, setAllowBasicAuth, setUserAgent ) import qualified Control.Exception as Exception -import Control.Exception - ( evaluate ) -import Control.DeepSeq - ( force ) -import Control.Monad - ( guard ) -import Distribution.Verbosity (Verbosity) -import Distribution.Pretty (prettyShow) import Distribution.Simple.Utils ( die', info, warn, debug, notice , copyFileVerbose, withTempFile, IOData (..) ) @@ -55,7 +47,6 @@ import System.IO ( withFile, IOMode(ReadMode), hGetContents, hClose ) import System.IO.Error ( isDoesNotExistError ) -import Distribution.Parsec (explicitEitherParsec) import Distribution.Simple.Program ( Program, simpleProgram, ConfiguredProgram, programPath , ProgramInvocation(..), programInvocation @@ -70,7 +61,6 @@ import Distribution.Simple.Program.Run ( getProgramInvocationOutputAndErrors ) import Numeric (showHex) import System.Random (randomRIO) -import System.Exit (ExitCode(..)) import qualified Crypto.Hash.SHA256 as SHA256 import qualified Data.ByteString.Base16 as Base16 diff --git a/cabal-install/Distribution/Client/IndexUtils.hs b/cabal-install/Distribution/Client/IndexUtils.hs index 5faa1b38ae8..cc286a580ee 100644 --- a/cabal-install/Distribution/Client/IndexUtils.hs +++ b/cabal-install/Distribution/Client/IndexUtils.hs @@ -54,8 +54,7 @@ import Distribution.Client.IndexUtils.IndexState import Distribution.Client.IndexUtils.Timestamp import Distribution.Client.Types import Distribution.Verbosity -import Distribution.Pretty (prettyShow) -import Distribution.Parsec (simpleParsec, simpleParsecBS) +import Distribution.Parsec (simpleParsecBS) import Distribution.Package ( PackageId, PackageIdentifier(..), mkPackageName @@ -89,8 +88,6 @@ import Distribution.Solver.Types.SourcePackage import qualified Data.Map as Map import qualified Data.Set as Set -import Control.DeepSeq -import Control.Monad import Control.Exception import Data.List (stripPrefix) import qualified Data.ByteString.Lazy as BS @@ -101,7 +98,6 @@ import Distribution.Client.GZipUtils (maybeDecompress) import Distribution.Client.Utils ( byteStringToFilePath , tryFindAddSourcePackageDesc ) import Distribution.Utils.Structured (Structured (..), nominalStructure, structuredEncodeFile, structuredDecodeFileOrFail) -import Distribution.Compat.Exception (catchIO) import Distribution.Compat.Time (getFileAge, getModTime) import System.Directory (doesFileExist, doesDirectoryExist) import System.FilePath @@ -230,7 +226,7 @@ getSourcePackagesAtIndexState verbosity repoCtxt mb_idxState mb_activeRepos = do let describeState IndexStateHead = "most recent state" describeState (IndexStateTime time) = "historical state as of " ++ prettyShow time - pkgss <- forM (repoContextRepos repoCtxt) $ \r -> do + pkgss <- for (repoContextRepos repoCtxt) $ \r -> do let rname :: RepoName rname = case r of RepoRemote remote _ -> remoteRepoName remote @@ -699,7 +695,7 @@ withIndexEntries verbosity (RepoIndex _repoCtxt (RepoLocalNoIndex (LocalRepo nam dirContents <- listDirectory localDir let contentSet = Set.fromList dirContents - entries <- handle handler $ fmap catMaybes $ forM dirContents $ \file -> do + entries <- handle handler $ fmap catMaybes $ for dirContents $ \file -> do case isTarGz file of Nothing -> do unless (takeFileName file == "noindex.cache" || ".cabal" `isSuffixOf` file) $ @@ -707,7 +703,7 @@ withIndexEntries verbosity (RepoIndex _repoCtxt (RepoLocalNoIndex (LocalRepo nam return Nothing Just pkgid | cabalPath `Set.member` contentSet -> do contents <- BSS.readFile (localDir cabalPath) - forM (parseGenericPackageDescriptionMaybe contents) $ \gpd -> + for (parseGenericPackageDescriptionMaybe contents) $ \gpd -> return (CacheGPD gpd contents) where cabalPath = prettyShow pkgid ++ ".cabal" diff --git a/cabal-install/Distribution/Client/IndexUtils/ActiveRepos.hs b/cabal-install/Distribution/Client/IndexUtils/ActiveRepos.hs index 5ba5b539756..931b8db9cf1 100644 --- a/cabal-install/Distribution/Client/IndexUtils/ActiveRepos.hs +++ b/cabal-install/Distribution/Client/IndexUtils/ActiveRepos.hs @@ -13,8 +13,7 @@ import Distribution.Client.Compat.Prelude import Distribution.Client.Types.RepoName (RepoName (..)) import Prelude () -import Distribution.Parsec (Parsec (..), parsecLeadingCommaNonEmpty) -import Distribution.Pretty (Pretty (..), prettyShow) +import Distribution.Parsec (parsecLeadingCommaNonEmpty) import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp diff --git a/cabal-install/Distribution/Client/IndexUtils/IndexState.hs b/cabal-install/Distribution/Client/IndexUtils/IndexState.hs index 5091e97e198..cbd01de141e 100644 --- a/cabal-install/Distribution/Client/IndexUtils/IndexState.hs +++ b/cabal-install/Distribution/Client/IndexUtils/IndexState.hs @@ -21,8 +21,7 @@ import Distribution.Client.Compat.Prelude import Distribution.Client.IndexUtils.Timestamp (Timestamp) import Distribution.Client.Types.RepoName (RepoName (..)) -import Distribution.Parsec (Parsec (..), parsecLeadingCommaNonEmpty) -import Distribution.Pretty (Pretty (..)) +import Distribution.Parsec (parsecLeadingCommaNonEmpty) import qualified Data.Map.Strict as Map import qualified Distribution.Compat.CharParsing as P diff --git a/cabal-install/Distribution/Client/IndexUtils/Timestamp.hs b/cabal-install/Distribution/Client/IndexUtils/Timestamp.hs index dea53ec3c74..48d3017d0e8 100644 --- a/cabal-install/Distribution/Client/IndexUtils/Timestamp.hs +++ b/cabal-install/Distribution/Client/IndexUtils/Timestamp.hs @@ -27,8 +27,6 @@ import Prelude (read) import Data.Time (UTCTime (..), fromGregorianValid, makeTimeOfDayValid, showGregorian, timeOfDayToTime, timeToTimeOfDay) import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds) -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) import qualified Codec.Archive.Tar.Entry as Tar import qualified Distribution.Compat.CharParsing as P diff --git a/cabal-install/Distribution/Client/Init/Command.hs b/cabal-install/Distribution/Client/Init/Command.hs index 12b4dd60799..5fcc8ab5cb7 100644 --- a/cabal-install/Distribution/Client/Init/Command.hs +++ b/cabal-install/Distribution/Client/Init/Command.hs @@ -32,11 +32,9 @@ import System.FilePath ( (), takeBaseName, equalFilePath ) import qualified Data.List.NonEmpty as NE -import Data.Function - ( on ) import qualified Data.Map as M import Control.Monad - ( (>=>), join, mapM ) + ( (>=>) ) import Control.Arrow ( (&&&), (***) ) @@ -45,8 +43,6 @@ import Distribution.CabalSpecVersion import Distribution.Version ( Version, mkVersion, alterVersion, majorBoundVersion , orLaterVersion, earlierVersion, intersectVersionRanges, VersionRange ) -import Distribution.Verbosity - ( Verbosity ) import Distribution.ModuleName ( ModuleName ) -- And for the Text instance import Distribution.InstalledPackageInfo @@ -85,10 +81,6 @@ import Distribution.Simple.Program ( ProgramDb ) import Distribution.Simple.PackageIndex ( InstalledPackageIndex, moduleNameIndex ) -import Distribution.Pretty - ( prettyShow ) -import Distribution.Parsec - ( eitherParsec ) import Distribution.Solver.Types.PackageIndex ( elemByPackageName ) @@ -657,7 +649,7 @@ importsToDeps flags mods pkgIx = do modDeps = map (id &&& flip M.lookup modMap) mods message flags "\nGuessing dependencies..." - nub . catMaybes <$> mapM (chooseDep flags) modDeps + nub . catMaybes <$> traverse (chooseDep flags) modDeps -- Given a module and a list of installed packages providing it, -- choose a dependency (i.e. package + version range) to use for that diff --git a/cabal-install/Distribution/Client/Init/Defaults.hs b/cabal-install/Distribution/Client/Init/Defaults.hs index 9d3de81226f..7f87a28f1f1 100644 --- a/cabal-install/Distribution/Client/Init/Defaults.hs +++ b/cabal-install/Distribution/Client/Init/Defaults.hs @@ -19,6 +19,8 @@ module Distribution.Client.Init.Defaults ( , myLibModule ) where +import Prelude (String) + import Distribution.ModuleName ( ModuleName ) -- And for the Text instance import qualified Distribution.ModuleName as ModuleName diff --git a/cabal-install/Distribution/Client/Init/FileCreators.hs b/cabal-install/Distribution/Client/Init/FileCreators.hs index 963428174cf..7fe3d67a8f4 100644 --- a/cabal-install/Distribution/Client/Init/FileCreators.hs +++ b/cabal-install/Distribution/Client/Init/FileCreators.hs @@ -34,13 +34,9 @@ import Distribution.Client.Compat.Prelude hiding (empty) import System.FilePath ( (), (<.>), takeExtension ) -import Distribution.Pretty (Pretty, pretty, prettyShow) import Distribution.Types.Dependency import Distribution.Types.VersionRange - -import Control.Monad - ( forM_ ) import Data.Time ( getCurrentTime, utcToLocalTime, toGregorian, localDay, getCurrentTimeZone ) import System.Directory @@ -184,7 +180,7 @@ writeFileSafe flags fileName content = do -- | Create directories, if they were given, and don't already exist. createDirectories :: Maybe [String] -> IO () createDirectories mdirs = case mdirs of - Just dirs -> forM_ dirs (createDirectoryIfMissing True) + Just dirs -> for_ dirs (createDirectoryIfMissing True) Nothing -> return () -- | Create MyLib.hs file, if its the only module in the liste. diff --git a/cabal-install/Distribution/Client/Init/Heuristics.hs b/cabal-install/Distribution/Client/Init/Heuristics.hs index 10effbe0235..1726dd06a68 100644 --- a/cabal-install/Distribution/Client/Init/Heuristics.hs +++ b/cabal-install/Distribution/Client/Init/Heuristics.hs @@ -24,7 +24,6 @@ import Prelude () import Distribution.Client.Compat.Prelude import Distribution.Utils.Generic (safeHead, safeTail, safeLast) -import Distribution.Parsec (simpleParsec) import Distribution.Simple.Setup (Flag(..), flagToMaybe) import Distribution.ModuleName ( ModuleName, toFilePath ) @@ -41,11 +40,8 @@ import Distribution.Solver.Types.SourcePackage ( packageDescription ) import Distribution.Client.Types ( SourcePackageDb(..) ) -import Control.Monad ( mapM ) -import Data.Char ( isNumber, isLower ) -import Data.Either ( partitionEithers ) +import Data.Char ( isLower ) import Data.List ( isInfixOf ) -import Data.Ord ( comparing ) import qualified Data.Set as Set ( fromList, toList ) import System.Directory ( getCurrentDirectory, getDirectoryContents, doesDirectoryExist, doesFileExist, getHomeDirectory, ) @@ -55,7 +51,6 @@ import System.FilePath ( takeExtension, takeBaseName, dropExtension, import Distribution.Client.Init.Types ( InitFlags(..) ) import Distribution.Client.Compat.Process ( readProcessWithExitCode ) -import System.Exit ( ExitCode(..) ) import qualified Distribution.Utils.ShortText as ShortText @@ -104,8 +99,8 @@ guessPackageName = liftM (P.mkPackageName . repair . fromMaybe "" . safeLast . s x' -> let (c, r) = first repairComponent $ break (not . isAlphaNum) x' in c ++ repairRest r where - repairComponent c | all isNumber c = invalid c - | otherwise = valid c + repairComponent c | all isDigit c = invalid c + | otherwise = valid c repairRest = repair' id ('-' :) -- |Data type of source files found in the working directory @@ -132,12 +127,12 @@ scanForModulesIn projectRoot srcRoot = scan srcRoot [] where scan dir hierarchy = do entries <- getDirectoryContents (projectRoot dir) - (files, dirs) <- liftM partitionEithers (mapM (tagIsDir dir) entries) + (files, dirs) <- liftM partitionEithers (traverse (tagIsDir dir) entries) let modules = catMaybes [ guessModuleName hierarchy file | file <- files , maybe False isUpper (safeHead file) ] - modules' <- mapM (findImportsAndExts projectRoot) modules - recMods <- mapM (scanRecursive dir hierarchy) dirs + modules' <- traverse (findImportsAndExts projectRoot) modules + recMods <- traverse (scanRecursive dir hierarchy) dirs return $ concat (modules' : recMods) tagIsDir parent entry = do isDir <- doesDirectoryExist (parent entry) diff --git a/cabal-install/Distribution/Client/Init/Licenses.hs b/cabal-install/Distribution/Client/Init/Licenses.hs index a8e19b13749..e08d3580fe3 100644 --- a/cabal-install/Distribution/Client/Init/Licenses.hs +++ b/cabal-install/Distribution/Client/Init/Licenses.hs @@ -23,6 +23,8 @@ module Distribution.Client.Init.Licenses , isc ) where +import Prelude (String, unlines, (++)) + type License = String bsd2 :: String -> String -> License diff --git a/cabal-install/Distribution/Client/Init/Prompt.hs b/cabal-install/Distribution/Client/Init/Prompt.hs index 8b9ae8277eb..00332782705 100644 --- a/cabal-install/Distribution/Client/Init/Prompt.hs +++ b/cabal-install/Distribution/Client/Init/Prompt.hs @@ -26,15 +26,8 @@ module Distribution.Client.Init.Prompt ( import Prelude () import Distribution.Client.Compat.Prelude hiding (empty) -import Control.Monad - ( mapM_ ) - import Distribution.Client.Init.Types ( InitFlags(..) ) -import Distribution.Parsec - ( Parsec, simpleParsec ) -import Distribution.Pretty - ( Pretty, prettyShow ) import Distribution.Simple.Setup ( Flag(..) ) @@ -76,15 +69,15 @@ promptDefault' :: (String -> Maybe t) -- ^ parser -> String -- ^ prompt message -> Maybe t -- ^ optional default value -> IO t -promptDefault' parser pretty pr def = do - putStr $ mkDefPrompt pr (pretty `fmap` def) +promptDefault' parser ppr pr def = do + putStr $ mkDefPrompt pr (ppr `fmap` def) inp <- getLine case (inp, def) of ("", Just d) -> return d _ -> case parser inp of Just t -> return t Nothing -> do putStrLn $ "Couldn't parse " ++ inp ++ ", please try again!" - promptDefault' parser pretty pr def + promptDefault' parser ppr pr def -- | Create a prompt from a prompt string and a String representation -- of an optional default value. @@ -126,7 +119,7 @@ promptList pr choices def displayItem other = do let options1 = map (\c -> (Just c == def, displayItem c)) choices options2 = zip ([1..]::[Int]) (options1 ++ [(False, "Other (specify)") | other]) - mapM_ (putStrLn . \(n,(i,s)) -> showOption n i ++ s) options2 + traverse_ (putStrLn . \(n,(i,s)) -> showOption n i ++ s) options2 promptList' displayItem (length options2) choices def other where showOption n i | n < 10 = " " ++ star i ++ " " ++ rest | otherwise = " " ++ star i ++ rest diff --git a/cabal-install/Distribution/Client/Init/Types.hs b/cabal-install/Distribution/Client/Init/Types.hs index f5ddf90742a..e92e026578d 100644 --- a/cabal-install/Distribution/Client/Init/Types.hs +++ b/cabal-install/Distribution/Client/Init/Types.hs @@ -32,8 +32,6 @@ import Language.Haskell.Extension ( Language(..), Extension ) import qualified Text.PrettyPrint as Disp import qualified Distribution.Compat.CharParsing as P import qualified Data.Map as Map -import Distribution.Pretty (Pretty (..)) -import Distribution.Parsec (Parsec (..)) -- | InitFlags is really just a simple type to represent certain -- portions of a .cabal file. Rather than have a flag for EVERY diff --git a/cabal-install/Distribution/Client/Init/Utils.hs b/cabal-install/Distribution/Client/Init/Utils.hs index d97b0c6f2df..a3cfe06fe4e 100644 --- a/cabal-install/Distribution/Client/Init/Utils.hs +++ b/cabal-install/Distribution/Client/Init/Utils.hs @@ -17,6 +17,9 @@ module Distribution.Client.Init.Utils ( , message ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Simple.Setup ( Flag(..) ) import Distribution.Client.Init.Types diff --git a/cabal-install/Distribution/Client/Install.hs b/cabal-install/Distribution/Client/Install.hs index c03dabb523c..49bd61d7893 100644 --- a/cabal-install/Distribution/Client/Install.hs +++ b/cabal-install/Distribution/Client/Install.hs @@ -36,18 +36,7 @@ import Distribution.Utils.Generic(safeLast) import qualified Data.List.NonEmpty as NE import qualified Data.Map as Map import Control.Exception as Exception - ( Exception(toException), bracket, catches - , Handler(Handler), handleJust, IOException, SomeException ) -#ifndef mingw32_HOST_OS -import Control.Exception as Exception - ( Exception(fromException) ) -#endif -import System.Exit - ( ExitCode(..) ) -import Distribution.Compat.Exception - ( catchIO, catchExit ) -import Control.Monad - ( forM_, mapM ) + ( bracket, catches, Handler(Handler), handleJust ) import System.Directory ( getTemporaryDirectory, doesDirectoryExist, doesFileExist, createDirectoryIfMissing, removeFile, renameDirectory, @@ -130,8 +119,7 @@ import qualified Distribution.Simple.Setup as Cabal , registerCommand, RegisterFlags(..), emptyRegisterFlags , testCommand, TestFlags(..) ) import Distribution.Simple.Utils - ( createDirectoryIfMissingVerbose, comparing - , writeFileAtomic ) + ( createDirectoryIfMissingVerbose, writeFileAtomic ) import Distribution.Simple.InstallDirs as InstallDirs ( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate , initialPathTemplateEnv, installDirsTemplateEnv ) @@ -145,7 +133,6 @@ import Distribution.Types.Dependency ( Dependency (..), mainLibSet ) import Distribution.Types.GivenComponent ( GivenComponent(..) ) -import Distribution.Pretty ( prettyShow ) import Distribution.Types.PackageVersionConstraint ( PackageVersionConstraint(..), thisPackageVersionConstraint ) import Distribution.Types.MungedPackageId @@ -167,7 +154,7 @@ import Distribution.Client.Utils import Distribution.System ( Platform, OS(Windows), buildOS, buildPlatform ) import Distribution.Verbosity as Verbosity - ( Verbosity, modifyVerbosity, normal, verbose ) + ( modifyVerbosity, normal, verbose ) import Distribution.Simple.BuildPaths ( exeExtension ) import qualified Data.ByteString as BS @@ -773,7 +760,7 @@ reportPlanningFailure verbosity -- Save solver log case logFile of Nothing -> return () - Just template -> forM_ pkgids $ \pkgid -> + Just template -> for_ pkgids $ \pkgid -> let env = initialPathTemplateEnv pkgid dummyIpid (compilerInfo comp) platform path = fromPathTemplate $ substPathTemplate env template @@ -1417,7 +1404,7 @@ installUnpackedPackage verbosity installLock numJobs let packageDBs = interpretPackageDbFlags (fromFlag (configUserInstall configFlags)) (configPackageDBs configFlags) - forM_ ipkgs' $ \ipkg' -> + for_ ipkgs' $ \ipkg' -> registerPackage verbosity comp progdb packageDBs ipkg' defaultRegisterOptions @@ -1494,7 +1481,7 @@ installUnpackedPackage verbosity installLock numJobs if is_dir -- Sort so that each prefix of the package -- configurations is well formed - then mapM (readPkgConf pkgConfDest) . sort . filter notHidden + then traverse (readPkgConf pkgConfDest) . sort . filter notHidden =<< getDirectoryContents pkgConfDest else fmap (:[]) $ readPkgConf "." pkgConfDest else return [] diff --git a/cabal-install/Distribution/Client/InstallPlan.hs b/cabal-install/Distribution/Client/InstallPlan.hs index 78ce6b3e7fb..953f96127e5 100644 --- a/cabal-install/Distribution/Client/InstallPlan.hs +++ b/cabal-install/Distribution/Client/InstallPlan.hs @@ -83,7 +83,7 @@ import Distribution.Package , HasUnitId(..), UnitId ) import Distribution.Solver.Types.SolverPackage import Distribution.Client.JobControl -import Distribution.Pretty (Pretty (..), prettyShow, defaultStyle) +import Distribution.Pretty (defaultStyle) import Text.PrettyPrint import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan import Distribution.Client.SolverInstallPlan (SolverInstallPlan) diff --git a/cabal-install/Distribution/Client/InstallSymlink.hs b/cabal-install/Distribution/Client/InstallSymlink.hs index fb48074e3e8..0c3c390794f 100644 --- a/cabal-install/Distribution/Client/InstallSymlink.hs +++ b/cabal-install/Distribution/Client/InstallSymlink.hs @@ -48,9 +48,7 @@ import Distribution.Simple.Compiler ( Compiler, compilerInfo, CompilerInfo(..) ) import Distribution.System ( Platform ) -import Distribution.Verbosity ( Verbosity ) import Distribution.Simple.Utils ( info, withTempDirectory ) -import Distribution.Pretty (prettyShow) import System.Directory ( canonicalizePath, getTemporaryDirectory, removeFile ) @@ -59,7 +57,6 @@ import System.FilePath import System.IO.Error ( isDoesNotExistError, ioError ) -import Distribution.Compat.Exception ( catchIO ) import Control.Exception ( assert ) diff --git a/cabal-install/Distribution/Client/JobControl.hs b/cabal-install/Distribution/Client/JobControl.hs index 9c9a212888c..28480512209 100644 --- a/cabal-install/Distribution/Client/JobControl.hs +++ b/cabal-install/Distribution/Client/JobControl.hs @@ -28,13 +28,16 @@ module Distribution.Client.JobControl ( criticalSection ) where -import Control.Monad +import Distribution.Client.Compat.Prelude +import Prelude () + +import Control.Monad (forever, replicateM_) import Control.Concurrent (forkIO) import Control.Concurrent.MVar import Control.Concurrent.STM (STM, atomically) import Control.Concurrent.STM.TVar import Control.Concurrent.STM.TChan -import Control.Exception (SomeException, bracket_, throwIO, try) +import Control.Exception (bracket_, try) import Distribution.Client.Compat.Semaphore diff --git a/cabal-install/Distribution/Client/List.hs b/cabal-install/Distribution/Client/List.hs index 02facc1e1c2..0a265efd506 100644 --- a/cabal-install/Distribution/Client/List.hs +++ b/cabal-install/Distribution/Client/List.hs @@ -30,20 +30,18 @@ import Distribution.PackageDescription ( PackageFlag(..), unFlagName ) import Distribution.PackageDescription.Configuration ( flattenPackageDescription ) -import Distribution.Pretty (pretty, prettyShow) import Distribution.Simple.Compiler ( Compiler, PackageDBStack ) import Distribution.Simple.Program (ProgramDb) import Distribution.Simple.Utils - ( equating, comparing, die', notice ) + ( equating, die', notice ) import Distribution.Simple.Setup (fromFlag, fromFlagOrDefault) import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex import Distribution.Version ( Version, mkVersion, versionNumbers, VersionRange, withinRange, anyVersion , intersectVersionRanges, simplifyVersionRange ) -import Distribution.Verbosity (Verbosity) import qualified Distribution.SPDX as SPDX @@ -67,21 +65,19 @@ import Distribution.Client.FetchUtils import Data.Bits ((.|.)) import Data.List - ( maximumBy, partition ) + ( maximumBy ) import Data.List.NonEmpty (groupBy, nonEmpty) import qualified Data.List as L import Data.Maybe ( fromJust ) import qualified Data.Map as Map import Data.Tree as Tree -import Control.Monad - ( join ) import Control.Exception ( assert ) import qualified Text.PrettyPrint as Disp import Text.PrettyPrint ( lineLength, ribbonsPerLine, Doc, renderStyle, char - , (<+>), nest, ($+$), text, vcat, style, parens, fsep) + , nest, ($+$), text, vcat, style, parens, fsep) import System.Directory ( doesDirectoryExist ) diff --git a/cabal-install/Distribution/Client/Manpage.hs b/cabal-install/Distribution/Client/Manpage.hs index d5641bf232d..60786bfeafd 100644 --- a/cabal-install/Distribution/Client/Manpage.hs +++ b/cabal-install/Distribution/Client/Manpage.hs @@ -28,7 +28,6 @@ import Distribution.Client.Setup (globalCommand) import Distribution.Compat.Process (createProcess) import Distribution.Simple.Command import Distribution.Simple.Flag (fromFlagOrDefault) -import System.Exit (exitWith) import System.IO (hClose, hPutStr) import qualified System.Process as Process diff --git a/cabal-install/Distribution/Client/ManpageFlags.hs b/cabal-install/Distribution/Client/ManpageFlags.hs index 7c2df85aa7e..79ed9e5dc6a 100644 --- a/cabal-install/Distribution/Client/ManpageFlags.hs +++ b/cabal-install/Distribution/Client/ManpageFlags.hs @@ -10,7 +10,7 @@ import Distribution.Client.Compat.Prelude import Distribution.Simple.Command (OptionField (..), ShowOrParseArgs (..), option) import Distribution.Simple.Setup (Flag (..), toFlag, trueArg, optionVerbosity) -import Distribution.Verbosity (Verbosity, normal) +import Distribution.Verbosity (normal) data ManpageFlags = ManpageFlags { manpageVerbosity :: Flag Verbosity diff --git a/cabal-install/Distribution/Client/Nix.hs b/cabal-install/Distribution/Client/Nix.hs index fbe89834572..4798f8e8be9 100644 --- a/cabal-install/Distribution/Client/Nix.hs +++ b/cabal-install/Distribution/Client/Nix.hs @@ -10,7 +10,7 @@ module Distribution.Client.Nix import Distribution.Client.Compat.Prelude -import Control.Exception (bracket, catch) +import Control.Exception (bracket) import System.Directory ( canonicalizePath, createDirectoryIfMissing, doesDirectoryExist , doesFileExist, removeDirectoryRecursive, removeFile ) @@ -24,8 +24,6 @@ import System.Process (showCommandForUser) import Distribution.Compat.Environment ( lookupEnv, setEnv, unsetEnv ) -import Distribution.Verbosity - import Distribution.Simple.Program ( Program(..), ProgramDb , addKnownProgram, configureProgram, emptyProgramDb, getDbProgramOutput @@ -84,7 +82,7 @@ nixInstantiate -> GlobalFlags -> SavedConfig -> IO () -nixInstantiate verb dist force globalFlags config = +nixInstantiate verb dist force' globalFlags config = findNixExpr globalFlags config >>= \case Nothing -> return () Just shellNix -> do @@ -96,7 +94,7 @@ nixInstantiate verb dist force globalFlags config = let timestamp = timestampPath dist shellNix upToDate <- existsAndIsMoreRecentThan timestamp shellNix - let ready = alreadyInShell || (instantiated && upToDate && not force) + let ready = alreadyInShell || (instantiated && upToDate && not force') unless ready $ do let prog = simpleProgram "nix-instantiate" diff --git a/cabal-install/Distribution/Client/Outdated.hs b/cabal-install/Distribution/Client/Outdated.hs index 10e0e6685eb..b153c3ab5d9 100644 --- a/cabal-install/Distribution/Client/Outdated.hs +++ b/cabal-install/Distribution/Client/Outdated.hs @@ -31,7 +31,6 @@ import Distribution.Utils.Generic import Distribution.Package (PackageName, packageVersion) import Distribution.PackageDescription (allBuildDepends) import Distribution.PackageDescription.Configuration (finalizePD) -import Distribution.Pretty (prettyShow) import Distribution.Simple.Compiler (Compiler, compilerInfo) import Distribution.Simple.Setup (fromFlagOrDefault, flagToMaybe) @@ -42,7 +41,7 @@ import Distribution.Types.ComponentRequestedSpec (ComponentRequestedSpec(..)) import Distribution.Types.Dependency (Dependency(..)) -import Distribution.Verbosity (Verbosity, silent) +import Distribution.Verbosity (silent) import Distribution.Version (Version, VersionRange, LowerBound(..), UpperBound(..) ,asVersionIntervals, majorBoundVersion) @@ -53,8 +52,6 @@ import Distribution.Types.PackageVersionConstraint import qualified Data.Set as S import System.Directory (getCurrentDirectory) -import System.Exit (exitFailure) -import Control.Exception (throwIO) -- | Entry point for the 'outdated' command. outdated :: Verbosity -> OutdatedFlags -> RepoContext diff --git a/cabal-install/Distribution/Client/PackageHash.hs b/cabal-install/Distribution/Client/PackageHash.hs index 6e87b7c0aab..cb6f492eee4 100644 --- a/cabal-install/Distribution/Client/PackageHash.hs +++ b/cabal-install/Distribution/Client/PackageHash.hs @@ -37,7 +37,6 @@ import Distribution.Simple.Compiler , ProfDetailLevel(..), showProfDetailLevel ) import Distribution.Simple.InstallDirs ( PathTemplate, fromPathTemplate ) -import Distribution.Pretty (prettyShow) import Distribution.Types.PkgconfigVersion (PkgconfigVersion) import Distribution.Client.HashValue import Distribution.Client.Types @@ -48,8 +47,6 @@ import qualified Data.ByteString.Lazy.Char8 as LBS import qualified Data.Map as Map import qualified Data.Set as Set -import Data.Function (on) - ------------------------------- -- Calculating package hashes -- diff --git a/cabal-install/Distribution/Client/PackageUtils.hs b/cabal-install/Distribution/Client/PackageUtils.hs index 8d84ec5ebd6..2a491f36212 100644 --- a/cabal-install/Distribution/Client/PackageUtils.hs +++ b/cabal-install/Distribution/Client/PackageUtils.hs @@ -14,6 +14,9 @@ module Distribution.Client.PackageUtils ( externalBuildDepends, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Package (packageName, packageVersion) import Distribution.PackageDescription (PackageDescription (..), enabledBuildDepends, libName) diff --git a/cabal-install/Distribution/Client/ParseUtils.hs b/cabal-install/Distribution/Client/ParseUtils.hs index c4c39df19f9..2e94cd4bc34 100644 --- a/cabal-install/Distribution/Client/ParseUtils.hs +++ b/cabal-install/Distribution/Client/ParseUtils.hs @@ -54,7 +54,7 @@ import Distribution.Deprecated.ViewAsFieldDescr import Distribution.Simple.Command ( OptionField ) -import Text.PrettyPrint ( (<+>), ($+$) ) +import Text.PrettyPrint ( ($+$) ) import qualified Data.Map as Map import qualified Text.PrettyPrint as Disp ( (<>), Doc, text, colon, vcat, empty, isEmpty, nest ) diff --git a/cabal-install/Distribution/Client/ProjectBuilding.hs b/cabal-install/Distribution/Client/ProjectBuilding.hs index cc348ea7e1d..fa305edd51a 100644 --- a/cabal-install/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/Distribution/Client/ProjectBuilding.hs @@ -90,8 +90,6 @@ import Distribution.Simple.Compiler import Distribution.Simple.Utils import Distribution.Version -import Distribution.Verbosity -import Distribution.Pretty import Distribution.Compat.Graph (IsNode(..)) import qualified Data.List.NonEmpty as NE @@ -100,8 +98,7 @@ import qualified Data.Set as Set import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS -import Control.Exception (Exception (..), Handler (..), SomeAsyncException, SomeException, assert, catches, handle, throwIO) -import Data.Function (on) +import Control.Exception (Handler (..), SomeAsyncException, assert, catches, handle) import System.Directory (canonicalizePath, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, removeFile, renameDirectory) import System.FilePath (dropDrive, makeRelative, normalise, takeDirectory, (<.>), ()) import System.IO (IOMode (AppendMode), withFile) diff --git a/cabal-install/Distribution/Client/ProjectBuilding/Types.hs b/cabal-install/Distribution/Client/ProjectBuilding/Types.hs index cd180d0db4f..f9ac571f3b6 100644 --- a/cabal-install/Distribution/Client/ProjectBuilding/Types.hs +++ b/cabal-install/Distribution/Client/ProjectBuilding/Types.hs @@ -22,6 +22,9 @@ module Distribution.Client.ProjectBuilding.Types ( BuildFailureReason(..), ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.Types (DocsResult, TestsResult) import Distribution.Client.FileMonitor (MonitorChangedReason(..)) @@ -29,11 +32,6 @@ import Distribution.Package (UnitId, PackageId) import Distribution.InstalledPackageInfo (InstalledPackageInfo) import Distribution.Simple.LocalBuildInfo (ComponentName) -import Data.Map (Map) -import Data.Set (Set) -import Data.Typeable (Typeable) -import Control.Exception (Exception, SomeException) - ------------------------------------------------------------------------------ -- Pre-build status: result of the dry run diff --git a/cabal-install/Distribution/Client/ProjectConfig.hs b/cabal-install/Distribution/Client/ProjectConfig.hs index 53c01b14eaf..ecf71d516ae 100644 --- a/cabal-install/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/Distribution/Client/ProjectConfig.hs @@ -99,7 +99,6 @@ import Distribution.PackageDescription.Parsec ( parseGenericPackageDescription ) import Distribution.Fields ( runParseResult, PError, PWarning, showPWarning) -import Distribution.Pretty (prettyShow) import Distribution.Types.SourceRepo ( RepoType(..) ) import Distribution.Client.Types.SourceRepo @@ -123,10 +122,9 @@ import Distribution.Client.Utils import Distribution.Utils.NubList ( fromNubList ) import Distribution.Verbosity - ( Verbosity, modifyVerbosity, verbose ) + ( modifyVerbosity, verbose ) import Distribution.Version ( Version ) -import Distribution.Parsec (simpleParsec) import qualified Distribution.Deprecated.ParseUtils as OldParser ( ParseResult(..), locatedErrorMsg, showPWarning ) @@ -135,10 +133,7 @@ import qualified Codec.Archive.Tar.Entry as Tar import qualified Distribution.Client.Tar as Tar import qualified Distribution.Client.GZipUtils as GZipUtils -import Control.Monad import Control.Monad.Trans (liftIO) -import Control.Exception -import Data.Either import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS import qualified Data.Map as Map @@ -809,7 +804,7 @@ findProjectPackages DistDirLayout{distProjectRootDirectory} where findPackageLocations required pkglocstr = do (problems, pkglocs) <- - partitionEithers <$> mapM (findPackageLocation required) pkglocstr + partitionEithers <$> traverse (findPackageLocation required) pkglocstr unless (null problems) $ liftIO $ throwIO $ BadPackageLocations projectConfigProvenance problems return (concat pkglocs) @@ -881,7 +876,7 @@ findProjectPackages DistDirLayout{distProjectRootDirectory} _ -> do (failures, pkglocs) <- partitionEithers <$> - mapM checkFilePackageMatch matches + traverse checkFilePackageMatch matches return $! case (failures, pkglocs) of ([failure], []) | isJust (isTrivialFilePathGlob glob) -> Left (BadPackageLocationFile failure) @@ -989,13 +984,13 @@ fetchAndReadSourcePackages verbosity distDirLayout pkgLocations = do pkgsLocalDirectory <- - sequence + sequenceA [ readSourcePackageLocalDirectory verbosity dir cabalFile | location <- pkgLocations , (dir, cabalFile) <- projectPackageLocal location ] pkgsLocalTarball <- - sequence + sequenceA [ readSourcePackageLocalTarball verbosity path | ProjectPackageLocalTarball path <- pkgLocations ] @@ -1003,7 +998,7 @@ fetchAndReadSourcePackages verbosity distDirLayout getTransport <- delayInitSharedResource $ configureTransport verbosity progPathExtra preferredHttpTransport - sequence + sequenceA [ fetchAndReadSourcePackageRemoteTarball verbosity distDirLayout getTransport uri | ProjectPackageRemoteTarball uri <- pkgLocations ] @@ -1147,7 +1142,7 @@ syncAndReadSourcePackagesRemoteRepos verbosity let vcs = Map.findWithDefault (error $ "Unknown VCS: " ++ prettyShow repoType) repoType knownVCSs in configureVCS verbosity {-progPathExtra-} vcs - concat <$> sequence + concat <$> sequenceA [ rerunIfChanged verbosity monitor repoGroup' $ do vcs' <- getConfiguredVCS repoType syncRepoGroupAndReadSourcePackages vcs' pathStem repoGroup' @@ -1178,7 +1173,7 @@ syncAndReadSourcePackagesRemoteRepos verbosity -- But for reading we go through each 'SourceRepo' including its subdir -- value and have to know which path each one ended up in. - sequence + sequenceA [ readPackageFromSourceRepo repoWithSubdir repoPath | (_, reposWithSubdir, repoPath) <- repoGroupWithPaths , repoWithSubdir <- NE.toList reposWithSubdir ] diff --git a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs index 85d988c591c..39a0342aa08 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs @@ -41,8 +41,6 @@ import Distribution.Client.CmdInstall.ClientInstallFlags import Distribution.Solver.Types.ConstraintSource import Distribution.FieldGrammar -import Distribution.Pretty (Pretty (..), prettyShow) -import Distribution.Parsec (Parsec (..), simpleParsec) import Distribution.Package import Distribution.Types.SourceRepo (RepoType) import Distribution.PackageDescription diff --git a/cabal-install/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/Distribution/Client/ProjectConfig/Types.hs index 877f3e8ebee..aca458f6032 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Types.hs @@ -64,8 +64,6 @@ import Distribution.Simple.InstallDirs ( PathTemplate ) import Distribution.Utils.NubList ( NubList ) -import Distribution.Verbosity - ( Verbosity ) import qualified Data.Map as Map diff --git a/cabal-install/Distribution/Client/ProjectOrchestration.hs b/cabal-install/Distribution/Client/ProjectOrchestration.hs index ff4deba5473..8881fb231ff 100644 --- a/cabal-install/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/Distribution/Client/ProjectOrchestration.hs @@ -158,19 +158,14 @@ import Distribution.Simple.Utils import Distribution.Verbosity import Distribution.Version ( mkVersion ) -import Distribution.Pretty - ( prettyShow ) import Distribution.Simple.Compiler ( compilerCompatVersion, showCompilerId , OptimisationLevel(..)) -import qualified Data.Monoid as Mon import qualified Data.List.NonEmpty as NE import qualified Data.Set as Set import qualified Data.Map as Map -import Data.Either -import Control.Exception (Exception(..), throwIO, assert) -import System.Exit (ExitCode(..), exitFailure) +import Control.Exception (assert) #ifdef MIN_VERSION_unix import System.Posix.Signals (sigKILL, sigSEGV) #endif @@ -949,7 +944,7 @@ printPlan verbosity computeEffectiveProfiling fullConfigureFlags partialConfigureFlags - = Mon.mempty { + = mempty { configProf = nubFlag False (configProf fullConfigureFlags), configProfExe = diff --git a/cabal-install/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/Distribution/Client/ProjectPlanOutput.hs index 062abb615ee..a131304ef85 100644 --- a/cabal-install/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/Distribution/Client/ProjectPlanOutput.hs @@ -44,7 +44,6 @@ import Distribution.Simple.GHC ( getImplInfo, GhcImplInfo(supportsPkgEnvFiles) , GhcEnvironmentFileEntry(..), simpleGhcEnvironmentFile , writeGhcEnvironmentFile ) -import Distribution.Pretty (Pretty, prettyShow) import qualified Distribution.Compat.Graph as Graph import Distribution.Compat.Graph (Graph, Node) import qualified Distribution.Compat.Binary as Binary diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index f2621a9106d..5c3a345c432 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -153,24 +153,18 @@ import Distribution.Types.ComponentInclude import Distribution.Simple.Utils import Distribution.Version -import Distribution.Verbosity -import Distribution.Pretty (pretty, prettyShow) import qualified Distribution.Compat.Graph as Graph import Distribution.Compat.Graph(IsNode(..)) -import Text.PrettyPrint hiding ((<>)) +import Text.PrettyPrint (text, hang, quotes, colon, vcat, ($$), fsep, punctuate, comma) import qualified Text.PrettyPrint as Disp import qualified Data.Map as Map import qualified Data.Set as Set -import Control.Monad -import qualified Data.Traversable as T import Control.Monad.State as State -import Control.Exception +import Control.Exception (assert) import Data.List (groupBy) import qualified Data.List.NonEmpty as NE -import Data.Either -import Data.Function import System.FilePath ------------------------------------------------------------------------------ @@ -774,7 +768,7 @@ getSourcePackages verbosity withRepoCtx idxState activeRepos = do sourcePkgDbWithTIS <- IndexUtils.getSourcePackagesAtIndexState verbosity repoctx idxState activeRepos return (sourcePkgDbWithTIS, repoContextRepos repoctx) - mapM_ needIfExists + traverse_ needIfExists . IndexUtils.getSourcePackagesMonitorFiles $ repos return sourcePkgDbWithTIS @@ -785,7 +779,7 @@ getPkgConfigDb verbosity progdb = do dirs <- liftIO $ getPkgConfigDbDirs verbosity progdb -- Just monitor the dirs so we'll notice new .pc files. -- Alternatively we could monitor all the .pc files too. - mapM_ monitorDirectoryStatus dirs + traverse_ monitorDirectoryStatus dirs liftIO $ readPkgConfigDb verbosity progdb @@ -2162,7 +2156,7 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan = = case planpkg of InstallPlan.Configured (elab0@ElaboratedConfiguredPackage { elabPkgOrComp = ElabComponent comp }) -> do - deps <- mapM (substUnitId insts) + deps <- traverse (substUnitId insts) (compLinkedLibDependencies comp) let getDep (Module dep_uid _) = [dep_uid] elab1 = elab0 { @@ -2198,7 +2192,7 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan = substSubst :: Map ModuleName Module -> Map ModuleName OpenModule -> InstM (Map ModuleName Module) - substSubst subst insts = T.mapM (substModule subst) insts + substSubst subst insts = traverse (substModule subst) insts substModule :: Map ModuleName Module -> OpenModule -> InstM Module substModule subst (OpenModuleVar mod_name) @@ -2235,7 +2229,7 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan = -- we initially created the ElaboratedPlanPackage because -- we have no way of actually refiying the UnitId into a -- DefiniteUnitId (that's what substUnitId does!) - new_deps <- forM (compLinkedLibDependencies elab_comp) $ \uid -> + new_deps <- for (compLinkedLibDependencies elab_comp) $ \uid -> if Set.null (openUnitIdFreeHoles uid) then fmap DefiniteUnitId (substUnitId Map.empty uid) else return uid @@ -2257,7 +2251,7 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan = ready_map = execState work Map.empty - work = forM_ pkgs $ \pkg -> + work = for_ pkgs $ \pkg -> case pkg of InstallPlan.Configured elab | not (Map.null (elabLinkedInstantiatedWith elab)) diff --git a/cabal-install/Distribution/Client/ProjectPlanning/Types.hs b/cabal-install/Distribution/Client/ProjectPlanning/Types.hs index 0a1f37b7ead..1d0e1c5d0ab 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning/Types.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning/Types.hs @@ -78,8 +78,7 @@ import Distribution.Client.DistDirLayout import Distribution.Backpack import Distribution.Backpack.ModuleShape -import Distribution.Pretty -import Distribution.Verbosity +import Distribution.Verbosity (normal) import Distribution.Types.ComponentRequestedSpec import Distribution.Types.PkgconfigVersion import Distribution.Types.PackageDescription (PackageDescription(..)) @@ -108,7 +107,6 @@ import Distribution.Simple.Utils (ordNub) import qualified Data.Map as Map import qualified Data.ByteString.Lazy as LBS import qualified Data.Monoid as Mon -import Control.Monad (guard) import System.FilePath (()) diff --git a/cabal-install/Distribution/Client/RebuildMonad.hs b/cabal-install/Distribution/Client/RebuildMonad.hs index 2e2829e9371..ec7e9843bdc 100644 --- a/cabal-install/Distribution/Client/RebuildMonad.hs +++ b/cabal-install/Distribution/Client/RebuildMonad.hs @@ -63,7 +63,6 @@ import Distribution.Client.Glob hiding (matchFileGlob) import qualified Distribution.Client.Glob as Glob (matchFileGlob) import Distribution.Simple.Utils (debug) -import Distribution.Verbosity (Verbosity) import qualified Data.Map.Strict as Map import Control.Monad.State as State diff --git a/cabal-install/Distribution/Client/Reconfigure.hs b/cabal-install/Distribution/Client/Reconfigure.hs index ced89b37a1f..cb15790e5dd 100644 --- a/cabal-install/Distribution/Client/Reconfigure.hs +++ b/cabal-install/Distribution/Client/Reconfigure.hs @@ -5,8 +5,6 @@ import Distribution.Client.Compat.Prelude import Data.Monoid ( Any(..) ) import System.Directory ( doesFileExist ) -import Distribution.Verbosity - import Distribution.Simple.Configure ( localBuildInfoFile ) import Distribution.Simple.Setup ( Flag, flagToMaybe, toFlag ) import Distribution.Simple.Utils @@ -126,11 +124,11 @@ reconfigure <> checkDist <> checkOutdated <> check - (Any force, flags@(configFlags, _)) <- runCheck checks mempty savedFlags + (Any frc, flags@(configFlags, _)) <- runCheck checks mempty savedFlags let config' = updateInstallDirs (configUserInstall configFlags) config - when force $ configureAction flags extraArgs globalFlags + when frc $ configureAction flags extraArgs globalFlags return config' where diff --git a/cabal-install/Distribution/Client/Run.hs b/cabal-install/Distribution/Client/Run.hs index c3d6262528d..47025ff849a 100644 --- a/cabal-install/Distribution/Client/Run.hs +++ b/cabal-install/Distribution/Client/Run.hs @@ -34,8 +34,6 @@ import Distribution.Simple.Utils (die', notice, warn, rawSystemExitWithEnv, addLibraryPath) import Distribution.System (Platform (..)) -import Distribution.Verbosity (Verbosity) -import Distribution.Pretty (prettyShow) import qualified Distribution.Simple.GHCJS as GHCJS diff --git a/cabal-install/Distribution/Client/Sandbox.hs b/cabal-install/Distribution/Client/Sandbox.hs index c5ddf1b8d97..ab1412c5d29 100644 --- a/cabal-install/Distribution/Client/Sandbox.hs +++ b/cabal-install/Distribution/Client/Sandbox.hs @@ -42,7 +42,6 @@ import Distribution.Simple.Program ( ProgramDb ) import Distribution.Simple.Setup ( Flag(..) , fromFlagOrDefault, flagToMaybe ) import Distribution.System ( Platform ) -import Distribution.Verbosity ( Verbosity ) import System.Directory ( getCurrentDirectory ) diff --git a/cabal-install/Distribution/Client/Sandbox/PackageEnvironment.hs b/cabal-install/Distribution/Client/Sandbox/PackageEnvironment.hs index 277ec914072..7ecab15ce10 100644 --- a/cabal-install/Distribution/Client/Sandbox/PackageEnvironment.hs +++ b/cabal-install/Distribution/Client/Sandbox/PackageEnvironment.hs @@ -22,6 +22,9 @@ module Distribution.Client.Sandbox.PackageEnvironment ( , userPackageEnvironmentFile ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Client.Config ( SavedConfig(..) , configFieldDescriptions , haddockFlagsFields @@ -44,23 +47,13 @@ import Distribution.Deprecated.ParseUtils ( FieldDescr(..), ParseResult( , readFields , showPWarning , syntaxError, warning ) -import Distribution.Verbosity ( Verbosity ) -import Control.Monad ( foldM, unless ) -import Data.List ( partition, sortBy ) -import Data.Ord ( comparing ) -import Distribution.Compat.Exception ( catchIO ) -import Distribution.Compat.Semigroup import System.Directory ( doesFileExist ) import System.FilePath ( () ) import System.IO.Error ( isDoesNotExistError ) import Text.PrettyPrint ( ($+$) ) -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) import qualified Text.PrettyPrint as Disp import qualified Distribution.Deprecated.ParseUtils as ParseUtils ( Field(..) ) -import GHC.Generics ( Generic ) - -- -- * Configuration saved in the package environment file diff --git a/cabal-install/Distribution/Client/SavedFlags.hs b/cabal-install/Distribution/Client/SavedFlags.hs index 44a104194f2..4b148360358 100644 --- a/cabal-install/Distribution/Client/SavedFlags.hs +++ b/cabal-install/Distribution/Client/SavedFlags.hs @@ -5,17 +5,15 @@ module Distribution.Client.SavedFlags , readSavedArgs, writeSavedArgs ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Simple.Command import Distribution.Simple.UserHooks ( Args ) import Distribution.Simple.Utils ( createDirectoryIfMissingVerbose, unintersperse ) import Distribution.Verbosity -import Control.Exception ( Exception, throwIO ) -import Control.Monad ( liftM ) -import Data.List ( intercalate ) -import Data.Maybe ( fromMaybe ) -import Data.Typeable import System.Directory ( doesFileExist ) import System.FilePath ( takeDirectory ) @@ -41,7 +39,7 @@ readSavedArgs :: FilePath -> IO (Maybe [String]) readSavedArgs path = do exists <- doesFileExist path if exists - then liftM (Just . unintersperse '\0') (readFile path) + then fmap (Just . unintersperse '\0') (readFile path) else return Nothing @@ -49,7 +47,7 @@ readSavedArgs path = do -- Returns the default flags if the file does not exist. readCommandFlags :: FilePath -> CommandUI flags -> IO flags readCommandFlags path command = do - savedArgs <- liftM (fromMaybe []) (readSavedArgs path) + savedArgs <- fmap (fromMaybe []) (readSavedArgs path) case (commandParseArgs command True savedArgs) of CommandHelp _ -> throwIO (SavedArgsErrorHelp savedArgs) CommandList _ -> throwIO (SavedArgsErrorList savedArgs) diff --git a/cabal-install/Distribution/Client/Security/DNS.hs b/cabal-install/Distribution/Client/Security/DNS.hs index 638c37e16d3..05f422636c6 100644 --- a/cabal-install/Distribution/Client/Security/DNS.hs +++ b/cabal-install/Distribution/Client/Security/DNS.hs @@ -7,12 +7,8 @@ module Distribution.Client.Security.DNS import Prelude () import Distribution.Client.Compat.Prelude import Network.URI (URI(..), URIAuth(..), parseURI) -import Distribution.Verbosity -import Control.Monad -import Control.DeepSeq (force) -import Control.Exception (SomeException, evaluate, try) +import Control.Exception (try) import Distribution.Simple.Utils -import Distribution.Compat.Exception (displayException) #if defined(MIN_VERSION_resolv) || defined(MIN_VERSION_windns) import Network.DNS (queryTXT, Name(..), CharStr(..)) @@ -70,7 +66,7 @@ queryBootstrapMirrors verbosity repoUri then warn verbosity ("No mirrors found for " ++ show repoUri) else do info verbosity ("located " ++ show (length mirrors) ++ " mirrors for " ++ show repoUri ++ " :") - forM_ mirrors $ \url -> info verbosity ("- " ++ show url) + for_ mirrors $ \url -> info verbosity ("- " ++ show url) return mirrors @@ -117,7 +113,7 @@ queryBootstrapMirrors verbosity repoUri then warn verbosity ("No mirrors found for " ++ show repoUri) else do info verbosity ("located " ++ show (length mirrors) ++ " mirrors for " ++ show repoUri ++ " :") - forM_ mirrors $ \url -> info verbosity ("- " ++ show url) + for_ mirrors $ \url -> info verbosity ("- " ++ show url) return mirrors diff --git a/cabal-install/Distribution/Client/Security/HTTP.hs b/cabal-install/Distribution/Client/Security/HTTP.hs index 07896fa72b6..44601181896 100644 --- a/cabal-install/Distribution/Client/Security/HTTP.hs +++ b/cabal-install/Distribution/Client/Security/HTTP.hs @@ -8,13 +8,10 @@ -- | Implementation of 'HttpLib' using cabal-install's own 'HttpTransport' module Distribution.Client.Security.HTTP (HttpLib, transportAdapter) where +import Distribution.Solver.Compat.Prelude +import Prelude () + -- stdlibs -import Control.Exception - ( Exception(..), IOException ) -import Data.List - ( intercalate ) -import Data.Typeable - ( Typeable ) import System.Directory ( getTemporaryDirectory ) import Network.URI @@ -31,10 +28,11 @@ import Distribution.Client.Utils ( withTempFileName ) -- hackage-security -import Hackage.Security.Client -import Hackage.Security.Client.Repository.HttpLib -import Hackage.Security.Util.Checked -import Hackage.Security.Util.Pretty +import Hackage.Security.Client.Repository.HttpLib (HttpLib (..)) +import qualified Hackage.Security.Client as HC +import qualified Hackage.Security.Client.Repository.HttpLib as HC +import qualified Hackage.Security.Util.Checked as HC +import qualified Hackage.Security.Util.Pretty as HC {------------------------------------------------------------------------------- 'HttpLib' implementation @@ -62,49 +60,50 @@ transportAdapter :: Verbosity -> IO HttpTransport -> HttpLib transportAdapter verbosity getTransport = HttpLib{ httpGet = \headers uri callback -> do transport <- getTransport - get verbosity transport headers uri callback + httpGetImpl verbosity transport headers uri callback , httpGetRange = \headers uri range callback -> do transport <- getTransport getRange verbosity transport headers uri range callback } -get :: Throws SomeRemoteError +httpGetImpl + :: HC.Throws HC.SomeRemoteError => Verbosity -> HttpTransport - -> [HttpRequestHeader] -> URI - -> ([HttpResponseHeader] -> BodyReader -> IO a) + -> [HC.HttpRequestHeader] -> URI + -> ([HC.HttpResponseHeader] -> HC.BodyReader -> IO a) -> IO a -get verbosity transport reqHeaders uri callback = wrapCustomEx $ do +httpGetImpl verbosity transport reqHeaders uri callback = wrapCustomEx $ do get' verbosity transport reqHeaders uri Nothing $ \code respHeaders br -> case code of 200 -> callback respHeaders br - _ -> throwChecked $ UnexpectedResponse uri code + _ -> HC.throwChecked $ UnexpectedResponse uri code -getRange :: Throws SomeRemoteError +getRange :: HC.Throws HC.SomeRemoteError => Verbosity -> HttpTransport - -> [HttpRequestHeader] -> URI -> (Int, Int) - -> (HttpStatus -> [HttpResponseHeader] -> BodyReader -> IO a) + -> [HC.HttpRequestHeader] -> URI -> (Int, Int) + -> (HC.HttpStatus -> [HC.HttpResponseHeader] -> HC.BodyReader -> IO a) -> IO a getRange verbosity transport reqHeaders uri range callback = wrapCustomEx $ do get' verbosity transport reqHeaders uri (Just range) $ \code respHeaders br -> case code of - 200 -> callback HttpStatus200OK respHeaders br - 206 -> callback HttpStatus206PartialContent respHeaders br - _ -> throwChecked $ UnexpectedResponse uri code + 200 -> callback HC.HttpStatus200OK respHeaders br + 206 -> callback HC.HttpStatus206PartialContent respHeaders br + _ -> HC.throwChecked $ UnexpectedResponse uri code -- | Internal generalization of 'get' and 'getRange' get' :: Verbosity -> HttpTransport - -> [HttpRequestHeader] -> URI -> Maybe (Int, Int) - -> (HttpCode -> [HttpResponseHeader] -> BodyReader -> IO a) + -> [HC.HttpRequestHeader] -> URI -> Maybe (Int, Int) + -> (HttpCode -> [HC.HttpResponseHeader] -> HC.BodyReader -> IO a) -> IO a get' verbosity transport reqHeaders uri mRange callback = do tempDir <- getTemporaryDirectory withTempFileName tempDir "transportAdapterGet" $ \temp -> do (code, _etag) <- getHttp transport verbosity uri Nothing temp reqHeaders' - br <- bodyReaderFromBS =<< BS.L.readFile temp - callback code [HttpResponseAcceptRangesBytes] br + br <- HC.bodyReaderFromBS =<< BS.L.readFile temp + callback code [HC.HttpResponseAcceptRangesBytes] br where reqHeaders' = mkReqHeaders reqHeaders mRange @@ -119,18 +118,18 @@ mkRangeHeader from to = HTTP.Header HTTP.HdrRange rangeHeader -- See rangeHeader = "bytes=" ++ show from ++ "-" ++ show (to - 1) -mkReqHeaders :: [HttpRequestHeader] -> Maybe (Int, Int) -> [HTTP.Header] +mkReqHeaders :: [HC.HttpRequestHeader] -> Maybe (Int, Int) -> [HTTP.Header] mkReqHeaders reqHeaders mRange = concat [ tr [] reqHeaders , [mkRangeHeader fr to | Just (fr, to) <- [mRange]] ] where - tr :: [(HTTP.HeaderName, [String])] -> [HttpRequestHeader] -> [HTTP.Header] + tr :: [(HTTP.HeaderName, [String])] -> [HC.HttpRequestHeader] -> [HTTP.Header] tr acc [] = concatMap finalize acc - tr acc (HttpRequestMaxAge0:os) = + tr acc (HC.HttpRequestMaxAge0:os) = tr (insert HTTP.HdrCacheControl ["max-age=0"] acc) os - tr acc (HttpRequestNoTransform:os) = + tr acc (HC.HttpRequestNoTransform:os) = tr (insert HTTP.HdrCacheControl ["no-transform"] acc) os -- Some headers are comma-separated, others need multiple headers for @@ -157,24 +156,24 @@ mkReqHeaders reqHeaders mRange = concat [ data UnexpectedResponse = UnexpectedResponse URI Int deriving (Typeable) -instance Pretty UnexpectedResponse where +instance HC.Pretty UnexpectedResponse where pretty (UnexpectedResponse uri code) = "Unexpected response " ++ show code ++ " for " ++ show uri #if MIN_VERSION_base(4,8,0) deriving instance Show UnexpectedResponse -instance Exception UnexpectedResponse where displayException = pretty +instance Exception UnexpectedResponse where displayException = HC.pretty #else -instance Show UnexpectedResponse where show = pretty +instance Show UnexpectedResponse where show = HC.pretty instance Exception UnexpectedResponse #endif -wrapCustomEx :: ( ( Throws UnexpectedResponse - , Throws IOException +wrapCustomEx :: ( ( HC.Throws UnexpectedResponse + , HC.Throws IOException ) => IO a) - -> (Throws SomeRemoteError => IO a) -wrapCustomEx act = handleChecked (\(ex :: UnexpectedResponse) -> go ex) - $ handleChecked (\(ex :: IOException) -> go ex) + -> (HC.Throws HC.SomeRemoteError => IO a) +wrapCustomEx act = HC.handleChecked (\(ex :: UnexpectedResponse) -> go ex) + $ HC.handleChecked (\(ex :: IOException) -> go ex) $ act where - go ex = throwChecked (SomeRemoteError ex) + go ex = HC.throwChecked (HC.SomeRemoteError ex) diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 5775dbd2c98..ec31ab523b6 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -79,8 +79,6 @@ import Distribution.Client.Targets ( UserConstraint, readUserConstraint ) import Distribution.Utils.NubList ( NubList, toNubList, fromNubList) -import Distribution.Parsec (CabalParsing, simpleParsec, parsec, eitherParsec) -import Distribution.Pretty (prettyShow) import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.Settings @@ -126,7 +124,7 @@ import Distribution.ReadE ( ReadE(..), succeedReadE, parsecToReadE ) import qualified Distribution.Compat.CharParsing as P import Distribution.Verbosity - ( Verbosity, lessVerbose, normal, verboseNoFlags, verboseNoTimestamp ) + ( lessVerbose, normal, verboseNoFlags, verboseNoTimestamp ) import Distribution.Simple.Utils ( wrapText ) import Distribution.Client.GlobalFlags diff --git a/cabal-install/Distribution/Client/SetupWrapper.hs b/cabal-install/Distribution/Client/SetupWrapper.hs index 4aae534a17b..0e7c3688f24 100644 --- a/cabal-install/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/Distribution/Client/SetupWrapper.hs @@ -87,7 +87,7 @@ import Distribution.Utils.Generic ( safeHead ) import Distribution.Simple.Utils ( die', debug, info, infoNoWrap - , cabalVersion, tryFindPackageDesc, comparing + , cabalVersion, tryFindPackageDesc , createDirectoryIfMissingVerbose, installExecutableFile , copyFileVerbose, rewriteFileEx, rewriteFileLBS ) import Distribution.Client.Utils @@ -100,18 +100,14 @@ import Distribution.Client.Utils import Distribution.ReadE import Distribution.System ( Platform(..), buildPlatform ) -import Distribution.Pretty (prettyShow) import Distribution.Utils.NubList ( toNubListR ) import Distribution.Verbosity -import Distribution.Compat.Exception - ( catchIO ) import Distribution.Compat.Stack import System.Directory ( doesFileExist ) import System.FilePath ( (), (<.>) ) import System.IO ( Handle, hPutStr ) -import System.Exit ( ExitCode(..), exitWith ) import Distribution.Compat.Process (createProcess) import System.Process ( StdStream(..), proc, waitForProcess , ProcessHandle ) diff --git a/cabal-install/Distribution/Client/SolverInstallPlan.hs b/cabal-install/Distribution/Client/SolverInstallPlan.hs index 723509e00a2..52106eb0774 100644 --- a/cabal-install/Distribution/Client/SolverInstallPlan.hs +++ b/cabal-install/Distribution/Client/SolverInstallPlan.hs @@ -58,8 +58,6 @@ import Distribution.Package ( PackageIdentifier(..), Package(..), PackageName , HasUnitId(..), PackageId, packageVersion, packageName ) import qualified Distribution.Solver.Types.ComponentDeps as CD -import Distribution.Pretty - ( prettyShow ) import Distribution.Client.Types ( UnresolvedPkgLoc ) diff --git a/cabal-install/Distribution/Client/SourceFiles.hs b/cabal-install/Distribution/Client/SourceFiles.hs index fdd51abb77b..b5057dabae5 100644 --- a/cabal-install/Distribution/Client/SourceFiles.hs +++ b/cabal-install/Distribution/Client/SourceFiles.hs @@ -37,7 +37,6 @@ import Prelude () import Distribution.Client.Compat.Prelude import System.FilePath -import Control.Monad import qualified Data.Set as Set needElaboratedConfiguredPackage :: ElaboratedConfiguredPackage -> Rebuild () @@ -48,7 +47,7 @@ needElaboratedConfiguredPackage elab = needElaboratedPackage :: ElaboratedConfiguredPackage -> ElaboratedPackage -> Rebuild () needElaboratedPackage elab epkg = - mapM_ (needComponent pkg_descr) (enabledComponents pkg_descr enabled) + traverse_ (needComponent pkg_descr) (enabledComponents pkg_descr enabled) where pkg_descr = elabPkgDescription elab enabled_stanzas = pkgStanzasEnabled epkg @@ -89,7 +88,7 @@ needLibrary pkg_descr (Library { exposedModules = modules needForeignLib :: PackageDescription -> ForeignLib -> Rebuild () needForeignLib pkg_descr (ForeignLib { foreignLibModDefFile = fs , foreignLibBuildInfo = bi }) - = do mapM_ needIfExists fs + = do traverse_ needIfExists fs needBuildInfo pkg_descr bi [] needExecutable :: PackageDescription -> Executable -> Rebuild () @@ -145,21 +144,21 @@ needBuildInfo pkg_descr bi modules = do -- A.hs-boot; need to track both. findNeededModules ["hs", "lhs", "hsig", "lhsig"] findNeededModules ["hs-boot", "lhs-boot"] - mapM_ needIfExists (cSources bi ++ jsSources bi) + traverse_ needIfExists (cSources bi ++ jsSources bi) -- A MASSIVE HACK to (1) make sure we rebuild when header -- files change, but (2) not have to rebuild when anything -- in extra-src-files changes (most of these won't affect -- compilation). It would be even better if we knew on a -- per-component basis which headers would be used but that -- seems to be too difficult. - mapM_ needIfExists (filter ((==".h").takeExtension) (extraSrcFiles pkg_descr)) - forM_ (installIncludes bi) $ \f -> + traverse_ needIfExists (filter ((==".h").takeExtension) (extraSrcFiles pkg_descr)) + for_ (installIncludes bi) $ \f -> findFileMonitored ("." : includeDirs bi) f >>= maybe (return ()) need where - findNeededModules exts = - mapM_ (findNeededModule exts) - (modules ++ otherModules bi) + findNeededModules exts = traverse_ + (findNeededModule exts) + (modules ++ otherModules bi) findNeededModule exts m = findFileWithExtensionMonitored (ppSuffixes knownSuffixHandlers ++ exts) diff --git a/cabal-install/Distribution/Client/SrcDist.hs b/cabal-install/Distribution/Client/SrcDist.hs index 5ef83b5f43a..8498d7202fa 100644 --- a/cabal-install/Distribution/Client/SrcDist.hs +++ b/cabal-install/Distribution/Client/SrcDist.hs @@ -3,6 +3,9 @@ module Distribution.Client.SrcDist ( allPackageSourceFiles, ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.PackageDescription.Configuration (flattenPackageDescription) import Distribution.PackageDescription.Parsec (readGenericPackageDescription) import Distribution.Simple.PreProcess (knownSuffixHandlers) diff --git a/cabal-install/Distribution/Client/Store.hs b/cabal-install/Distribution/Client/Store.hs index 61297386ff4..d78fb3dcc92 100644 --- a/cabal-install/Distribution/Client/Store.hs +++ b/cabal-install/Distribution/Client/Store.hs @@ -33,11 +33,10 @@ import Distribution.Compiler (CompilerId) import Distribution.Simple.Utils ( withTempDirectory, debug, info ) import Distribution.Verbosity -import Distribution.Pretty (prettyShow) + ( silent ) import qualified Data.Set as Set import Control.Exception -import Control.Monad (forM_) import System.FilePath import System.Directory @@ -214,7 +213,7 @@ newStoreEntry verbosity storeDirLayout@StoreDirLayout{..} -- Atomically rename the temp dir to the final store entry location. renameDirectory incomingEntryDir finalEntryDir - forM_ otherFiles $ \file -> do + for_ otherFiles $ \file -> do let finalStoreFile = storeDirectory compid makeRelative (incomingTmpDir (dropDrive (storeDirectory compid))) file createDirectoryIfMissing True (takeDirectory finalStoreFile) renameFile file finalStoreFile diff --git a/cabal-install/Distribution/Client/Tar.hs b/cabal-install/Distribution/Client/Tar.hs index 51427da0086..d59dcf8160a 100644 --- a/cabal-install/Distribution/Client/Tar.hs +++ b/cabal-install/Distribution/Client/Tar.hs @@ -28,6 +28,9 @@ module Distribution.Client.Tar ( entriesToList, ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import qualified Data.ByteString.Lazy as BS import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar.Entry as Tar @@ -35,7 +38,8 @@ import qualified Codec.Archive.Tar.Check as Tar import qualified Codec.Compression.GZip as GZip import qualified Distribution.Client.GZipUtils as GZipUtils -import Control.Exception (Exception(..), throw) +-- for foldEntries... +import Control.Exception (throw) -- -- * High level operations diff --git a/cabal-install/Distribution/Client/TargetSelector.hs b/cabal-install/Distribution/Client/TargetSelector.hs index 3e89ccd28b2..1ea5375341d 100644 --- a/cabal-install/Distribution/Client/TargetSelector.hs +++ b/cabal-install/Distribution/Client/TargetSelector.hs @@ -49,7 +49,6 @@ import Distribution.Types.UnqualComponentName import Distribution.Client.Types ( PackageLocation(..), PackageSpecifier(..) ) -import Distribution.Verbosity import Distribution.PackageDescription ( PackageDescription , Executable(..) @@ -66,23 +65,15 @@ import Distribution.Simple.LocalBuildInfo ( Component(..), ComponentName(..), LibraryName(..) , pkgComponents, componentName, componentBuildInfo ) import Distribution.Types.ForeignLib -import Distribution.Parsec (Parsec (..), simpleParsec) -import Distribution.Pretty (prettyShow) import Distribution.Simple.Utils ( die', lowercase, ordNub ) import Distribution.Client.Utils ( makeRelativeCanonical ) -import Data.Either - ( partitionEithers ) -import Data.Function - ( on ) import Data.List - ( stripPrefix, partition, groupBy ) + ( stripPrefix, groupBy ) import qualified Data.List.NonEmpty as NE -import Data.Ord - ( comparing ) import qualified Data.Map.Lazy as Map.Lazy import qualified Data.Map.Strict as Map import qualified Data.Set as Set @@ -225,7 +216,7 @@ readTargetSelectorsWith :: (Applicative m, Monad m) => DirActions m readTargetSelectorsWith dirActions@DirActions{} pkgs mfilter targetStrs = case parseTargetStrings targetStrs of ([], usertargets) -> do - usertargets' <- mapM (getTargetStringFileStatus dirActions) usertargets + usertargets' <- traverse (getTargetStringFileStatus dirActions) usertargets knowntargets <- getKnownTargets dirActions pkgs case resolveTargetSelectors knowntargets usertargets' mfilter of ([], btargets) -> return (Right btargets) @@ -1727,7 +1718,7 @@ getKnownTargets :: (Applicative m, Monad m) -> [PackageSpecifier (SourcePackage (PackageLocation a))] -> m KnownTargets getKnownTargets dirActions@DirActions{..} pkgs = do - pinfo <- mapM (collectKnownPackageInfo dirActions) pkgs + pinfo <- traverse (collectKnownPackageInfo dirActions) pkgs cwd <- getCurrentDirectory let (ppinfo, opinfo) = selectPrimaryPackage cwd pinfo return KnownTargets { diff --git a/cabal-install/Distribution/Client/Targets.hs b/cabal-install/Distribution/Client/Targets.hs index 234bf583bb5..71bb7f30fc3 100644 --- a/cabal-install/Distribution/Client/Targets.hs +++ b/cabal-install/Distribution/Client/Targets.hs @@ -82,22 +82,15 @@ import Distribution.Types.Flag ( nullFlagAssignment, parsecFlagAssignmentNonEmpty ) import Distribution.Version ( anyVersion, isAnyVersion ) -import Distribution.Pretty (Pretty (..), prettyShow) -import Distribution.Parsec (Parsec (..), CabalParsing, explicitEitherParsec, eitherParsec) -import Distribution.Verbosity (Verbosity) import Distribution.Simple.Utils ( die', warn, lowercase ) import Distribution.PackageDescription.Parsec ( readGenericPackageDescription, parseGenericPackageDescriptionMaybe ) --- import Data.List ( find, nub ) -import Data.Either - ( partitionEithers ) import qualified Data.Map as Map import qualified Data.ByteString.Lazy as BS import qualified Distribution.Client.GZipUtils as GZipUtils -import Control.Monad (mapM) import qualified Distribution.Compat.CharParsing as P import System.FilePath ( takeExtension, dropExtension, takeDirectory, splitPath ) @@ -170,7 +163,7 @@ data UserTarget = readUserTargets :: Verbosity -> [String] -> IO [UserTarget] readUserTargets verbosity targetStrs = do (problems, targets) <- liftM partitionEithers - (mapM readUserTarget targetStrs) + (traverse readUserTarget targetStrs) reportUserTargetProblems verbosity problems return targets @@ -316,9 +309,9 @@ resolveUserTargets verbosity repoCtxt worldFile available userTargets = do -- given the user targets, get a list of fully or partially resolved -- package references - packageTargets <- mapM (readPackageTarget verbosity) - =<< mapM (fetchPackageTarget verbosity repoCtxt) . concat - =<< mapM (expandUserTarget verbosity worldFile) userTargets + packageTargets <- traverse (readPackageTarget verbosity) + =<< traverse (fetchPackageTarget verbosity repoCtxt) . concat + =<< traverse (expandUserTarget verbosity worldFile) userTargets -- users are allowed to give package names case-insensitively, so we must -- disambiguate named package references diff --git a/cabal-install/Distribution/Client/Types/AllowNewer.hs b/cabal-install/Distribution/Client/Types/AllowNewer.hs index 594d63a1025..809f9f690be 100644 --- a/cabal-install/Distribution/Client/Types/AllowNewer.hs +++ b/cabal-install/Distribution/Client/Types/AllowNewer.hs @@ -14,8 +14,7 @@ module Distribution.Client.Types.AllowNewer ( import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Parsec (CabalParsing, Parsec (..), parsecLeadingCommaNonEmpty) -import Distribution.Pretty (Pretty (..)) +import Distribution.Parsec (parsecLeadingCommaNonEmpty) import Distribution.Types.PackageId (PackageId, PackageIdentifier (..)) import Distribution.Types.PackageName (PackageName, mkPackageName) import Distribution.Types.Version (nullVersion) diff --git a/cabal-install/Distribution/Client/Types/BuildResults.hs b/cabal-install/Distribution/Client/Types/BuildResults.hs index 4ecea97a2fb..4a3e7067b93 100644 --- a/cabal-install/Distribution/Client/Types/BuildResults.hs +++ b/cabal-install/Distribution/Client/Types/BuildResults.hs @@ -11,8 +11,6 @@ module Distribution.Client.Types.BuildResults ( import Distribution.Client.Compat.Prelude import Prelude () -import Control.Exception (Exception, SomeException) - import Distribution.Types.InstalledPackageInfo (InstalledPackageInfo) import Distribution.Types.PackageId (PackageId) import Distribution.Types.UnitId (UnitId) diff --git a/cabal-install/Distribution/Client/Types/Credentials.hs b/cabal-install/Distribution/Client/Types/Credentials.hs index 89be60a8af1..1b555718b85 100644 --- a/cabal-install/Distribution/Client/Types/Credentials.hs +++ b/cabal-install/Distribution/Client/Types/Credentials.hs @@ -3,5 +3,7 @@ module Distribution.Client.Types.Credentials ( Password (..), ) where +import Prelude (String) + newtype Username = Username { unUsername :: String } newtype Password = Password { unPassword :: String } diff --git a/cabal-install/Distribution/Client/Types/InstallMethod.hs b/cabal-install/Distribution/Client/Types/InstallMethod.hs index d59ffa2335c..c850b66f411 100644 --- a/cabal-install/Distribution/Client/Types/InstallMethod.hs +++ b/cabal-install/Distribution/Client/Types/InstallMethod.hs @@ -4,9 +4,6 @@ module Distribution.Client.Types.InstallMethod where import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) - import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as PP diff --git a/cabal-install/Distribution/Client/Types/OverwritePolicy.hs b/cabal-install/Distribution/Client/Types/OverwritePolicy.hs index 4163d219223..e2b43fdcedd 100644 --- a/cabal-install/Distribution/Client/Types/OverwritePolicy.hs +++ b/cabal-install/Distribution/Client/Types/OverwritePolicy.hs @@ -4,9 +4,6 @@ module Distribution.Client.Types.OverwritePolicy where import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) - import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as PP diff --git a/cabal-install/Distribution/Client/Types/Repo.hs b/cabal-install/Distribution/Client/Types/Repo.hs index 71f1e253415..804a78e430e 100644 --- a/cabal-install/Distribution/Client/Types/Repo.hs +++ b/cabal-install/Distribution/Client/Types/Repo.hs @@ -18,8 +18,6 @@ import Prelude () import Network.URI (URI (..), nullURI, parseAbsoluteURI, uriToString) -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) import Distribution.Simple.Utils (toUTF8BS) import Distribution.Client.HashValue (hashValue, showHashValue, truncateHash) diff --git a/cabal-install/Distribution/Client/Types/RepoName.hs b/cabal-install/Distribution/Client/Types/RepoName.hs index 3faba8233ca..cccf8673adf 100644 --- a/cabal-install/Distribution/Client/Types/RepoName.hs +++ b/cabal-install/Distribution/Client/Types/RepoName.hs @@ -7,9 +7,6 @@ module Distribution.Client.Types.RepoName ( import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Parsec (Parsec (..)) -import Distribution.Pretty (Pretty (..)) - import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp diff --git a/cabal-install/Distribution/Client/Update.hs b/cabal-install/Distribution/Client/Update.hs index 6cb3eeb846f..c918b7d402d 100644 --- a/cabal-install/Distribution/Client/Update.hs +++ b/cabal-install/Distribution/Client/Update.hs @@ -15,6 +15,9 @@ module Distribution.Client.Update ( update ) where +import Distribution.Client.Compat.Prelude +import Prelude () + import Distribution.Simple.Setup ( fromFlag ) import Distribution.Client.Compat.Directory @@ -34,9 +37,7 @@ import Distribution.Client.JobControl ( newParallelJobControl, spawnJob, collectJob ) import Distribution.Client.Setup ( RepoContext(..), UpdateFlags(..) ) -import Distribution.Pretty - ( prettyShow ) -import Distribution.Verbosity +import Distribution.Verbosity (lessVerbose) import Distribution.Simple.Utils ( writeFileAtomic, warn, notice, noticeNoWrap ) @@ -44,9 +45,7 @@ import Distribution.Simple.Utils import qualified Data.ByteString.Lazy as BS import Distribution.Client.GZipUtils (maybeDecompress) import System.FilePath ((<.>), dropExtension) -import Data.Maybe (mapMaybe) import Data.Time (getCurrentTime) -import Control.Monad import qualified Hackage.Security.Client as Sec @@ -67,8 +66,8 @@ update verbosity updateFlags repoCtxt = do $ "Downloading the latest package lists from: " : map (("- " ++) . unRepoName . remoteRepoName) remoteRepos jobCtrl <- newParallelJobControl (length repos) - mapM_ (spawnJob jobCtrl . updateRepo verbosity updateFlags repoCtxt) repos - mapM_ (\_ -> collectJob jobCtrl) repos + traverse_ (spawnJob jobCtrl . updateRepo verbosity updateFlags repoCtxt) repos + traverse_ (\_ -> collectJob jobCtrl) repos updateRepo :: Verbosity -> UpdateFlags -> RepoContext -> Repo -> IO () updateRepo verbosity updateFlags repoCtxt repo = do diff --git a/cabal-install/Distribution/Client/Upload.hs b/cabal-install/Distribution/Client/Upload.hs index 3459cf45d8b..17a25cd2ad9 100644 --- a/cabal-install/Distribution/Client/Upload.hs +++ b/cabal-install/Distribution/Client/Upload.hs @@ -1,5 +1,8 @@ module Distribution.Client.Upload (upload, uploadDoc, report) where +import Distribution.Client.Compat.Prelude +import qualified Prelude as Unsafe (tail, head, read) + import Distribution.Client.Types.Credentials ( Username(..), Password(..) ) import Distribution.Client.Types.Repo (RemoteRepo(..), maybeRepoRemote) import Distribution.Client.Types.RepoName (unRepoName) @@ -9,8 +12,6 @@ import Distribution.Client.Setup ( IsCandidate(..), RepoContext(..) ) import Distribution.Simple.Utils (notice, warn, info, die', toUTF8BS) -import Distribution.Verbosity (Verbosity) -import Distribution.Pretty (prettyShow) import Distribution.Client.Config import qualified Distribution.Client.BuildReports.Anonymous as BuildReport @@ -22,13 +23,9 @@ import Network.HTTP (Header(..), HeaderName(..)) import System.IO (hFlush, stdout) import System.IO.Echo (withoutInputEcho) -import System.Exit (exitFailure) import System.FilePath ((), takeExtension, takeFileName, dropExtension) import qualified System.FilePath.Posix as FilePath.Posix (()) import System.Directory -import Control.Monad (forM_, when, foldM) -import Data.Maybe (mapMaybe) -import Data.Char (isSpace) type Auth = Maybe (String, String) @@ -52,7 +49,7 @@ upload verbosity repoCtxt mUsername mPassword isCandidate paths = do targetRepo <- case [ remoteRepo | Just remoteRepo <- map maybeRepoRemote repos ] of [] -> die' verbosity "Cannot upload. No remote repositories are configured." - rs -> remoteRepoTryUpgradeToHttps verbosity transport (last rs) + (r:rs) -> remoteRepoTryUpgradeToHttps verbosity transport (last (r:|rs)) let targetRepoURI = remoteRepoURI targetRepo domain = maybe "Hackage" uriRegName $ uriAuthority targetRepoURI rootIfEmpty x = if null x then "/" else x @@ -74,7 +71,7 @@ upload verbosity repoCtxt mUsername mPassword isCandidate paths = do Username username <- maybe (promptUsername domain) return mUsername Password password <- maybe (promptPassword domain) return mPassword let auth = Just (username,password) - forM_ paths $ \path -> do + for_ paths $ \path -> do notice verbosity $ "Uploading " ++ path ++ "... " case fmap takeFileName (stripExtensions ["tar", "gz"] path) of Just pkgid -> handlePackage transport verbosity uploadURI @@ -92,7 +89,7 @@ uploadDoc verbosity repoCtxt mUsername mPassword isCandidate path = do targetRepo <- case [ remoteRepo | Just remoteRepo <- map maybeRepoRemote repos ] of [] -> die' verbosity $ "Cannot upload. No remote repositories are configured." - rs -> remoteRepoTryUpgradeToHttps verbosity transport (last rs) + (r:rs) -> remoteRepoTryUpgradeToHttps verbosity transport (last (r:|rs)) let targetRepoURI = remoteRepoURI targetRepo domain = maybe "Hackage" uriRegName $ uriAuthority targetRepoURI rootIfEmpty x = if null x then "/" else x @@ -117,9 +114,9 @@ uploadDoc verbosity repoCtxt mUsername mPassword isCandidate path = do } (reverseSuffix, reversePkgid) = break (== '-') (reverse (takeFileName path)) - pkgid = reverse $ tail reversePkgid + pkgid = reverse $ Unsafe.tail reversePkgid when (reverse reverseSuffix /= "docs.tar.gz" - || null reversePkgid || head reversePkgid /= '-') $ + || null reversePkgid || Unsafe.head reversePkgid /= '-') $ die' verbosity "Expected a file name matching the pattern -docs.tar.gz" Username username <- maybe (promptUsername domain) return mUsername Password password <- maybe (promptPassword domain) return mPassword @@ -172,7 +169,7 @@ report :: Verbosity -> RepoContext -> Maybe Username -> Maybe Password -> IO () report verbosity repoCtxt mUsername mPassword = do let repos = repoContextRepos repoCtxt remoteRepos = mapMaybe maybeRepoRemote repos - forM_ remoteRepos $ \remoteRepo -> do + for_ remoteRepos $ \remoteRepo -> do let domain = maybe "Hackage" uriRegName $ uriAuthority (remoteRepoURI remoteRepo) Username username <- maybe (promptUsername domain) return mUsername Password password <- maybe (promptPassword domain) return mPassword @@ -185,9 +182,9 @@ report verbosity repoCtxt mUsername mPassword = do srcExists <- doesDirectoryExist srcDir when srcExists $ do contents <- getDirectoryContents srcDir - forM_ (filter (\c -> takeExtension c ==".log") contents) $ \logFile -> + for_ (filter (\c -> takeExtension c ==".log") contents) $ \logFile -> do inp <- readFile (srcDir logFile) - let (reportStr, buildLog) = read inp :: (String,String) -- TODO: eradicateNoParse + let (reportStr, buildLog) = Unsafe.read inp :: (String,String) -- TODO: eradicateNoParse case parseBuildReport (toUTF8BS reportStr) of Left errs -> warn verbosity $ "Errors: " ++ errs -- FIXME Right report' -> diff --git a/cabal-install/Distribution/Client/Utils.hs b/cabal-install/Distribution/Client/Utils.hs index bc7bde50ef5..0ff2aa1c45a 100644 --- a/cabal-install/Distribution/Client/Utils.hs +++ b/cabal-install/Distribution/Client/Utils.hs @@ -27,18 +27,16 @@ import Prelude () import Distribution.Client.Compat.Prelude import Distribution.Compat.Environment -import Distribution.Compat.Exception ( catchIO ) -import Distribution.Compat.Time ( getModTime ) +import Distribution.Compat.Time ( getModTime ) import Distribution.Simple.Setup ( Flag(..) ) import Distribution.Version -import Distribution.Verbosity import Distribution.Simple.Utils ( die', findPackageDesc, noticeNoWrap ) import qualified Data.ByteString.Lazy as BS import Data.Bits ( (.|.), shiftL, shiftR ) import System.FilePath import Control.Monad - ( mapM, mapM_, zipWithM_ ) + ( zipWithM_ ) import Data.List ( groupBy ) import Foreign.C.Types ( CInt(..) ) @@ -149,8 +147,8 @@ withEnv k v m = do -- environment is a process-global concept. withEnvOverrides :: [(String, Maybe FilePath)] -> IO a -> IO a withEnvOverrides overrides m = do - mb_olds <- mapM lookupEnv envVars - mapM_ (uncurry update) overrides + mb_olds <- traverse lookupEnv envVars + traverse_ (uncurry update) overrides m `Exception.finally` zipWithM_ update envVars mb_olds where envVars :: [String] diff --git a/cabal-install/Distribution/Client/Utils/Assertion.hs b/cabal-install/Distribution/Client/Utils/Assertion.hs index d1b554ab64c..05dc0e8fe54 100644 --- a/cabal-install/Distribution/Client/Utils/Assertion.hs +++ b/cabal-install/Distribution/Client/Utils/Assertion.hs @@ -1,9 +1,13 @@ {-# LANGUAGE CPP #-} module Distribution.Client.Utils.Assertion (expensiveAssert) where + #ifdef DEBUG_EXPENSIVE_ASSERTIONS +import Prelude (Bool) import Control.Exception (assert) import Distribution.Compat.Stack +#else +import Prelude (Bool, id) #endif -- | Like 'assert', but only enabled with -fdebug-expensive-assertions. This diff --git a/cabal-install/Distribution/Client/VCS.hs b/cabal-install/Distribution/Client/VCS.hs index f5f96ea1292..49addef110c 100644 --- a/cabal-install/Distribution/Client/VCS.hs +++ b/cabal-install/Distribution/Client/VCS.hs @@ -40,7 +40,7 @@ import Distribution.Client.Types.SourceRepo (SourceRepoMaybe, SourceRepositoryPa import Distribution.Client.RebuildMonad ( Rebuild, monitorFiles, MonitorFilePath, monitorDirectoryExistence ) import Distribution.Verbosity as Verbosity - ( Verbosity, normal ) + ( normal ) import Distribution.Simple.Program ( Program(programFindVersion) , ConfiguredProgram(programVersion) @@ -51,14 +51,10 @@ import Distribution.Version ( mkVersion ) import qualified Distribution.PackageDescription as PD -import Control.Monad - ( mapM_ ) import Control.Monad.Trans ( liftIO ) import qualified Data.Char as Char import qualified Data.Map as Map -import Data.Either - ( partitionEithers ) import System.FilePath ( takeDirectory ) import System.Directory @@ -187,7 +183,7 @@ cloneSourceRepo -> IO () cloneSourceRepo verbosity vcs repo@SourceRepositoryPackage{ srpLocation = srcuri } destdir = - mapM_ (runProgramInvocation verbosity) invocations + traverse_ (runProgramInvocation verbosity) invocations where invocations = vcsCloneRepo vcs verbosity (vcsProgram vcs) repo diff --git a/cabal-install/Distribution/Client/Win32SelfUpgrade.hs b/cabal-install/Distribution/Client/Win32SelfUpgrade.hs index 324fb95d518..0d9a9effe59 100644 --- a/cabal-install/Distribution/Client/Win32SelfUpgrade.hs +++ b/cabal-install/Distribution/Client/Win32SelfUpgrade.hs @@ -42,6 +42,9 @@ module Distribution.Client.Win32SelfUpgrade ( deleteOldExeFile, ) where +import Distribution.Client.Compat.Prelude hiding (log) +import Prelude () + #ifdef mingw32_HOST_OS import qualified System.Win32 as Win32 @@ -51,10 +54,9 @@ import System.Process (runProcess) import System.Directory (canonicalizePath) import System.FilePath (takeBaseName, replaceBaseName, equalFilePath) -import Distribution.Verbosity as Verbosity (Verbosity, showForCabal) +import Distribution.Verbosity as Verbosity (showForCabal) import Distribution.Simple.Utils (debug, info) -import Prelude hiding (log) -- | If one of the given files is our own exe file then we arrange things such -- that the nested action can replace our own exe file. @@ -68,7 +70,7 @@ possibleSelfUpgrade :: Verbosity possibleSelfUpgrade verbosity newPaths action = do dstPath <- canonicalizePath =<< Win32.getModuleFileName Win32.nullHANDLE - newPaths' <- mapM canonicalizePath newPaths + newPaths' <- traverse canonicalizePath newPaths let doingSelfUpgrade = any (equalFilePath dstPath) newPaths' if not doingSelfUpgrade @@ -211,7 +213,6 @@ setEvent handle = #else -import Distribution.Verbosity (Verbosity) import Distribution.Simple.Utils (die') possibleSelfUpgrade :: Verbosity diff --git a/cabal-install/Distribution/Client/World.hs b/cabal-install/Distribution/Client/World.hs index 4ce8b8a8440..a24a663dfca 100644 --- a/cabal-install/Distribution/Client/World.hs +++ b/cabal-install/Distribution/Client/World.hs @@ -37,14 +37,9 @@ import Distribution.Types.Dependency import Distribution.Types.Flag ( FlagAssignment, unFlagAssignment , unFlagName, parsecFlagAssignmentNonEmpty ) -import Distribution.Verbosity - ( Verbosity ) import Distribution.Simple.Utils ( die', info, chattyTry, writeFileAtomic ) -import Distribution.Parsec (Parsec (..), CabalParsing, simpleParsec) -import Distribution.Pretty (Pretty (..), prettyShow) import qualified Distribution.Compat.CharParsing as P -import Distribution.Compat.Exception ( catchIO ) import qualified Text.PrettyPrint as Disp import Data.List diff --git a/cabal-install/Distribution/Deprecated/ParseUtils.hs b/cabal-install/Distribution/Deprecated/ParseUtils.hs index f95c6c91f67..67de8dfd2ca 100644 --- a/cabal-install/Distribution/Deprecated/ParseUtils.hs +++ b/cabal-install/Distribution/Deprecated/ParseUtils.hs @@ -57,7 +57,7 @@ import Text.PrettyPrint (Doc, punctuate, comma, fsep, sep) import qualified Text.Read as Read import qualified Control.Monad.Fail as Fail -import Distribution.Parsec (ParsecParser, explicitEitherParsec, parsecLeadingCommaList, parsecLeadingOptCommaList) +import Distribution.Parsec (ParsecParser, parsecLeadingCommaList, parsecLeadingOptCommaList) -- ----------------------------------------------------------------------------- diff --git a/cabal-install/Distribution/Deprecated/ViewAsFieldDescr.hs b/cabal-install/Distribution/Deprecated/ViewAsFieldDescr.hs index 88357ac8760..2a9cb99ebf8 100644 --- a/cabal-install/Distribution/Deprecated/ViewAsFieldDescr.hs +++ b/cabal-install/Distribution/Deprecated/ViewAsFieldDescr.hs @@ -6,8 +6,6 @@ import Distribution.Client.Compat.Prelude hiding (get) import Prelude () import qualified Data.List.NonEmpty as NE -import Distribution.Parsec (parsec) -import Distribution.Pretty import Distribution.ReadE (parsecToReadE) import Distribution.Simple.Command import Text.PrettyPrint (cat, comma, punctuate, text) diff --git a/cabal-install/Distribution/Solver/Modular.hs b/cabal-install/Distribution/Solver/Modular.hs index a938b6af294..c0c4f7a2d35 100644 --- a/cabal-install/Distribution/Solver/Modular.hs +++ b/cabal-install/Distribution/Solver/Modular.hs @@ -17,7 +17,6 @@ import Distribution.Solver.Compat.Prelude import qualified Data.Map as M import Data.Set (isSubsetOf) -import Data.Ord import Distribution.Compat.Graph ( IsNode(..) ) import Distribution.Compiler diff --git a/cabal-install/Distribution/Solver/Modular/Explore.hs b/cabal-install/Distribution/Solver/Modular/Explore.hs index 3ac28a462ad..bd5aa581b34 100644 --- a/cabal-install/Distribution/Solver/Modular/Explore.hs +++ b/cabal-install/Distribution/Solver/Modular/Explore.hs @@ -3,13 +3,14 @@ {-# LANGUAGE ScopedTypeVariables #-} module Distribution.Solver.Modular.Explore (backjumpAndExplore) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import qualified Distribution.Solver.Types.Progress as P -import Data.Foldable as F -import Data.List as L (foldl') -import Data.Maybe (fromMaybe) -import Data.Map.Strict as M -import Data.Set as S +import qualified Data.List as L (foldl') +import qualified Data.Map.Strict as M +import qualified Data.Set as S import Distribution.Simple.Setup (asBool) @@ -81,7 +82,7 @@ backjump :: forall w k a . Maybe Int -> ExploreState -> ConflictSetLog a backjump mbj enableBj fineGrainedConflicts couldResolveConflicts logSkippedChoice var lastCS xs = - F.foldr combine avoidGoal [(k, v) | (_, k, v) <- W.toList xs] CS.empty Nothing + foldr combine avoidGoal [(k, v) | (_, k, v) <- W.toList xs] CS.empty Nothing where combine :: (k, ExploreState -> ConflictSetLog a) -> (ConflictSet -> Maybe ConflictSet -> ExploreState -> ConflictSetLog a) @@ -269,7 +270,7 @@ exploreLog mbj enableBj fineGrainedConflicts (CountConflicts countConflicts) idx -- to be merged with the previous one. couldResolveConflicts :: QPN -> POption -> S.Set CS.Conflict -> Maybe ConflictSet couldResolveConflicts currentQPN@(Q _ pn) (POption i@(I v _) _) conflicts = - let (PInfo deps _ _ _) = idx ! pn ! i + let (PInfo deps _ _ _) = idx M.! pn M.! i qdeps = qualifyDeps (defaultQualifyOptions idx) currentQPN deps couldBeResolved :: CS.Conflict -> Maybe ConflictSet @@ -277,7 +278,7 @@ exploreLog mbj enableBj fineGrainedConflicts (CountConflicts countConflicts) idx couldBeResolved (CS.GoalConflict conflictingDep) = -- Check whether this package instance also has 'conflictingDep' -- as a dependency (ignoring flag and stanza choices). - if F.null [() | Simple (LDep _ (Dep (PkgComponent qpn _) _)) _ <- qdeps, qpn == conflictingDep] + if null [() | Simple (LDep _ (Dep (PkgComponent qpn _) _)) _ <- qdeps, qpn == conflictingDep] then Nothing else Just CS.empty couldBeResolved (CS.VersionConstraintConflict dep excludedVersion) = diff --git a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs index bc84228ce7e..f48144c15b3 100644 --- a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs +++ b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs @@ -2,11 +2,11 @@ module Distribution.Solver.Modular.IndexConversion ( convPIs ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import qualified Data.List as L -import Data.Map.Strict (Map) import qualified Data.Map.Strict as M -import Data.Maybe (mapMaybe, fromMaybe, maybeToList) -import Data.Monoid as Mon import qualified Data.Set as S import qualified Distribution.InstalledPackageInfo as IPI @@ -90,7 +90,7 @@ convId ipi = (pn, I ver $ Inst $ IPI.installedUnitId ipi) -- | Convert a single installed package into the solver-specific format. convIP :: SI.InstalledPackageIndex -> IPI.InstalledPackageInfo -> (PN, I, PInfo) convIP idx ipi = - case mapM (convIPId (DependencyReason pn M.empty S.empty) comp idx) (IPI.depends ipi) of + case traverse (convIPId (DependencyReason pn M.empty S.empty) comp idx) (IPI.depends ipi) of Nothing -> (pn, i, PInfo [] M.empty M.empty (Just Broken)) Just fds -> ( pn , i @@ -182,7 +182,7 @@ convGPD os arch cinfo constraints strfl solveExes pn ipns = S.fromList $ [ unqualComponentNameToPackageName nm | (nm, _) <- sub_libs ] - conv :: Mon.Monoid a => Component -> (a -> BuildInfo) -> DependencyReason PN -> + conv :: Monoid a => Component -> (a -> BuildInfo) -> DependencyReason PN -> CondTree ConfVar [Dependency] a -> FlaggedDeps PN conv comp getInfo dr = convCondTree M.empty dr pkg os arch cinfo pn fds comp getInfo ipns solveExes . diff --git a/cabal-install/Distribution/Solver/Modular/LabeledGraph.hs b/cabal-install/Distribution/Solver/Modular/LabeledGraph.hs index ce35247a7e7..bf5d0f71615 100644 --- a/cabal-install/Distribution/Solver/Modular/LabeledGraph.hs +++ b/cabal-install/Distribution/Solver/Modular/LabeledGraph.hs @@ -17,10 +17,11 @@ module Distribution.Solver.Modular.LabeledGraph ( , topSort ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Data.Array import Data.Graph (Vertex, Bounds) -import Data.List (sortBy) -import Data.Maybe (mapMaybe) import qualified Data.Graph as G {------------------------------------------------------------------------------- diff --git a/cabal-install/Distribution/Solver/Modular/Linking.hs b/cabal-install/Distribution/Solver/Modular/Linking.hs index d5522cd9d89..bbfaf9a635d 100644 --- a/cabal-install/Distribution/Solver/Modular/Linking.hs +++ b/cabal-install/Distribution/Solver/Modular/Linking.hs @@ -13,7 +13,6 @@ import Distribution.Solver.Compat.Prelude hiding (get,put) import Control.Exception (assert) import Control.Monad.Reader import Control.Monad.State -import Data.Function (on) import Data.Map ((!)) import qualified Data.Map as M import qualified Data.Set as S diff --git a/cabal-install/Distribution/Solver/Modular/Preference.hs b/cabal-install/Distribution/Solver/Modular/Preference.hs index 5eb2c6a1bf9..d25ef846356 100644 --- a/cabal-install/Distribution/Solver/Modular/Preference.hs +++ b/cabal-install/Distribution/Solver/Modular/Preference.hs @@ -21,11 +21,9 @@ module Distribution.Solver.Modular.Preference import Prelude () import Distribution.Solver.Compat.Prelude -import Data.Function (on) import qualified Data.List as L import qualified Data.Map as M -import Control.Monad.Reader hiding (sequence) -import Data.Traversable (sequence) +import Control.Monad.Trans.Reader (Reader, runReader, ask, local) import Distribution.PackageDescription (lookupFlagAssignment, unFlagAssignment) -- from Cabal @@ -462,7 +460,7 @@ enforceSingleInstanceRestriction = (`runReader` M.empty) . cata go -- We just verify package choices. go (PChoiceF qpn rdm gr cs) = - PChoice qpn rdm gr <$> sequence (W.mapWithKey (goP qpn) cs) + PChoice qpn rdm gr <$> sequenceA (W.mapWithKey (goP qpn) cs) go _otherwise = innM _otherwise diff --git a/cabal-install/Distribution/Solver/Modular/RetryLog.hs b/cabal-install/Distribution/Solver/Modular/RetryLog.hs index e1c39103dc7..0386eb18dd2 100644 --- a/cabal-install/Distribution/Solver/Modular/RetryLog.hs +++ b/cabal-install/Distribution/Solver/Modular/RetryLog.hs @@ -11,6 +11,9 @@ module Distribution.Solver.Modular.RetryLog , tryWith ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Solver.Modular.Message import Distribution.Solver.Types.Progress diff --git a/cabal-install/Distribution/Solver/Modular/Solver.hs b/cabal-install/Distribution/Solver/Modular/Solver.hs index 5a72155e823..83c597cd9e6 100644 --- a/cabal-install/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/Distribution/Solver/Modular/Solver.hs @@ -9,6 +9,9 @@ module Distribution.Solver.Modular.Solver , PruneAfterFirstSuccess(..) ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import qualified Data.Map as M import qualified Data.List as L import qualified Data.Set as S diff --git a/cabal-install/Distribution/Solver/Modular/Version.hs b/cabal-install/Distribution/Solver/Modular/Version.hs index 0bb6f8dde36..695a90aea99 100644 --- a/cabal-install/Distribution/Solver/Modular/Version.hs +++ b/cabal-install/Distribution/Solver/Modular/Version.hs @@ -11,6 +11,9 @@ module Distribution.Solver.Modular.Version , (.||.) ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import qualified Distribution.Version as CV -- from Cabal import Distribution.Pretty (prettyShow) diff --git a/cabal-install/Distribution/Solver/Types/ConstraintSource.hs b/cabal-install/Distribution/Solver/Types/ConstraintSource.hs index 2ab6888b0a6..2853f3e08c8 100644 --- a/cabal-install/Distribution/Solver/Types/ConstraintSource.hs +++ b/cabal-install/Distribution/Solver/Types/ConstraintSource.hs @@ -4,9 +4,8 @@ module Distribution.Solver.Types.ConstraintSource , showConstraintSource ) where -import GHC.Generics (Generic) -import Distribution.Compat.Binary (Binary) -import Distribution.Utils.Structured (Structured) +import Distribution.Solver.Compat.Prelude +import Prelude () -- | Source of a 'PackageConstraint'. data ConstraintSource = diff --git a/cabal-install/Distribution/Solver/Types/DependencyResolver.hs b/cabal-install/Distribution/Solver/Types/DependencyResolver.hs index bf20cc04534..e773492ae74 100644 --- a/cabal-install/Distribution/Solver/Types/DependencyResolver.hs +++ b/cabal-install/Distribution/Solver/Types/DependencyResolver.hs @@ -2,7 +2,8 @@ module Distribution.Solver.Types.DependencyResolver ( DependencyResolver ) where -import Data.Set (Set) +import Distribution.Solver.Compat.Prelude +import Prelude () import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.PkgConfigDb ( PkgConfigDb ) diff --git a/cabal-install/Distribution/Solver/Types/Flag.hs b/cabal-install/Distribution/Solver/Types/Flag.hs index 6c4f2180225..18ce1df3243 100644 --- a/cabal-install/Distribution/Solver/Types/Flag.hs +++ b/cabal-install/Distribution/Solver/Types/Flag.hs @@ -2,5 +2,7 @@ module Distribution.Solver.Types.Flag ( FlagType(..) ) where +import Prelude (Eq, Show) + data FlagType = Manual | Automatic deriving (Eq, Show) diff --git a/cabal-install/Distribution/Solver/Types/InstSolverPackage.hs b/cabal-install/Distribution/Solver/Types/InstSolverPackage.hs index 1464b8ed01e..871a0dd15a9 100644 --- a/cabal-install/Distribution/Solver/Types/InstSolverPackage.hs +++ b/cabal-install/Distribution/Solver/Types/InstSolverPackage.hs @@ -3,8 +3,9 @@ module Distribution.Solver.Types.InstSolverPackage ( InstSolverPackage(..) ) where -import Distribution.Compat.Binary (Binary(..)) -import Distribution.Utils.Structured (Structured) +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Package ( Package(..), HasMungedPackageId(..), HasUnitId(..) ) import Distribution.Solver.Types.ComponentDeps ( ComponentDeps ) import Distribution.Solver.Types.SolverId @@ -12,7 +13,6 @@ import Distribution.Types.MungedPackageId import Distribution.Types.PackageId import Distribution.Types.MungedPackageName import Distribution.InstalledPackageInfo (InstalledPackageInfo) -import GHC.Generics (Generic) -- | An 'InstSolverPackage' is a pre-existing installed package -- specified by the dependency solver. diff --git a/cabal-install/Distribution/Solver/Types/InstalledPreference.hs b/cabal-install/Distribution/Solver/Types/InstalledPreference.hs index 22c345e1fb9..88e0bddd10e 100644 --- a/cabal-install/Distribution/Solver/Types/InstalledPreference.hs +++ b/cabal-install/Distribution/Solver/Types/InstalledPreference.hs @@ -2,6 +2,8 @@ module Distribution.Solver.Types.InstalledPreference ( InstalledPreference(..), ) where +import Prelude (Show) + -- | Whether we prefer an installed version of a package or simply the latest -- version. -- diff --git a/cabal-install/Distribution/Solver/Types/OptionalStanza.hs b/cabal-install/Distribution/Solver/Types/OptionalStanza.hs index 4ec3bd881c8..d10a06311aa 100644 --- a/cabal-install/Distribution/Solver/Types/OptionalStanza.hs +++ b/cabal-install/Distribution/Solver/Types/OptionalStanza.hs @@ -6,13 +6,10 @@ module Distribution.Solver.Types.OptionalStanza , enableStanzas ) where -import GHC.Generics (Generic) -import Data.Typeable -import Distribution.Compat.Binary (Binary) +import Distribution.Solver.Compat.Prelude +import Prelude () import Distribution.Types.ComponentRequestedSpec (ComponentRequestedSpec(..), defaultComponentRequestedSpec) -import Data.List (foldl') -import Distribution.Utils.Structured (Structured) data OptionalStanza = TestStanzas diff --git a/cabal-install/Distribution/Solver/Types/PackageConstraint.hs b/cabal-install/Distribution/Solver/Types/PackageConstraint.hs index 84711721dc8..fbe56380e81 100644 --- a/cabal-install/Distribution/Solver/Types/PackageConstraint.hs +++ b/cabal-install/Distribution/Solver/Types/PackageConstraint.hs @@ -18,20 +18,18 @@ module Distribution.Solver.Types.PackageConstraint ( packageConstraintToDependency ) where -import Distribution.Compat.Binary (Binary) +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Package (PackageName) import Distribution.PackageDescription (FlagAssignment, dispFlagAssignment) import Distribution.Pretty (flatStyle, pretty) import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (..)) -import Distribution.Utils.Structured (Structured) import Distribution.Version (VersionRange, simplifyVersionRange) -import Distribution.Solver.Compat.Prelude ((<<>>)) import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackagePath -import GHC.Generics (Generic) -import Text.PrettyPrint ((<+>)) import qualified Text.PrettyPrint as Disp diff --git a/cabal-install/Distribution/Solver/Types/PackageIndex.hs b/cabal-install/Distribution/Solver/Types/PackageIndex.hs index 8cc2206435c..0963d284346 100644 --- a/cabal-install/Distribution/Solver/Types/PackageIndex.hs +++ b/cabal-install/Distribution/Solver/Types/PackageIndex.hs @@ -61,7 +61,7 @@ import Distribution.Package import Distribution.Version ( VersionRange, withinRange ) import Distribution.Simple.Utils - ( lowercase, comparing ) + ( lowercase ) import qualified Prelude (foldr1) diff --git a/cabal-install/Distribution/Solver/Types/PackagePath.hs b/cabal-install/Distribution/Solver/Types/PackagePath.hs index b7c0683dfe0..4fc4df25f97 100644 --- a/cabal-install/Distribution/Solver/Types/PackagePath.hs +++ b/cabal-install/Distribution/Solver/Types/PackagePath.hs @@ -9,10 +9,11 @@ module Distribution.Solver.Types.PackagePath , showQPN ) where -import Distribution.Package +import Distribution.Solver.Compat.Prelude +import Prelude () +import Distribution.Package (PackageName) import Distribution.Pretty (pretty, flatStyle) import qualified Text.PrettyPrint as Disp -import Distribution.Solver.Compat.Prelude ((<<>>)) -- | A package path consists of a namespace and a package path inside that -- namespace. diff --git a/cabal-install/Distribution/Solver/Types/PkgConfigDb.hs b/cabal-install/Distribution/Solver/Types/PkgConfigDb.hs index 07e7c567133..725fb124bf5 100644 --- a/cabal-install/Distribution/Solver/Types/PkgConfigDb.hs +++ b/cabal-install/Distribution/Solver/Types/PkgConfigDb.hs @@ -23,7 +23,7 @@ module Distribution.Solver.Types.PkgConfigDb import Distribution.Solver.Compat.Prelude import Prelude () -import Control.Exception (IOException, handle) +import Control.Exception (handle) import qualified Data.Map as M import System.FilePath (splitSearchPath) diff --git a/cabal-install/Distribution/Solver/Types/ResolverPackage.hs b/cabal-install/Distribution/Solver/Types/ResolverPackage.hs index 71655abd26a..840e58aff94 100644 --- a/cabal-install/Distribution/Solver/Types/ResolverPackage.hs +++ b/cabal-install/Distribution/Solver/Types/ResolverPackage.hs @@ -6,17 +6,17 @@ module Distribution.Solver.Types.ResolverPackage , resolverPackageExeDeps ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Solver.Types.InstSolverPackage import Distribution.Solver.Types.SolverId import Distribution.Solver.Types.SolverPackage import qualified Distribution.Solver.Types.ComponentDeps as CD -import Distribution.Compat.Binary (Binary) -import Distribution.Utils.Structured (Structured) import Distribution.Compat.Graph (IsNode(..)) import Distribution.Package (Package(..), HasUnitId(..)) import Distribution.Simple.Utils (ordNub) -import GHC.Generics (Generic) -- | The dependency resolver picks either pre-existing installed packages -- or it picks source packages along with package configuration. diff --git a/cabal-install/Distribution/Solver/Types/Settings.hs b/cabal-install/Distribution/Solver/Types/Settings.hs index 3ec49cd242f..38358ab9f85 100644 --- a/cabal-install/Distribution/Solver/Types/Settings.hs +++ b/cabal-install/Distribution/Solver/Types/Settings.hs @@ -15,12 +15,12 @@ module Distribution.Solver.Types.Settings , SolveExecutables(..) ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Simple.Setup ( BooleanFlag(..) ) -import Distribution.Compat.Binary (Binary) -import Distribution.Utils.Structured (Structured) import Distribution.Pretty ( Pretty(pretty) ) import Distribution.Parsec ( Parsec(parsec) ) -import GHC.Generics (Generic) import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as PP diff --git a/cabal-install/Distribution/Solver/Types/SolverId.hs b/cabal-install/Distribution/Solver/Types/SolverId.hs index 2d96ed19a8a..d32ccc17e74 100644 --- a/cabal-install/Distribution/Solver/Types/SolverId.hs +++ b/cabal-install/Distribution/Solver/Types/SolverId.hs @@ -5,10 +5,10 @@ module Distribution.Solver.Types.SolverId where -import Distribution.Compat.Binary (Binary) -import Distribution.Utils.Structured (Structured) +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Package (PackageId, Package(..), UnitId) -import GHC.Generics (Generic) -- | The solver can produce references to existing packages or -- packages we plan to install. Unlike 'ConfiguredId' we don't diff --git a/cabal-install/Distribution/Solver/Types/SolverPackage.hs b/cabal-install/Distribution/Solver/Types/SolverPackage.hs index f561af956c4..16b0a8f909d 100644 --- a/cabal-install/Distribution/Solver/Types/SolverPackage.hs +++ b/cabal-install/Distribution/Solver/Types/SolverPackage.hs @@ -3,15 +3,15 @@ module Distribution.Solver.Types.SolverPackage ( SolverPackage(..) ) where -import Distribution.Compat.Binary (Binary) -import Distribution.Utils.Structured (Structured) +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Package ( Package(..) ) import Distribution.PackageDescription ( FlagAssignment ) import Distribution.Solver.Types.ComponentDeps ( ComponentDeps ) import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.SolverId import Distribution.Solver.Types.SourcePackage -import GHC.Generics (Generic) -- | A 'SolverPackage' is a package specified by the dependency solver. -- It will get elaborated into a 'ConfiguredPackage' or even an diff --git a/cabal-install/Distribution/Solver/Types/SourcePackage.hs b/cabal-install/Distribution/Solver/Types/SourcePackage.hs index af0f8dd43dc..c7379c753a3 100644 --- a/cabal-install/Distribution/Solver/Types/SourcePackage.hs +++ b/cabal-install/Distribution/Solver/Types/SourcePackage.hs @@ -5,16 +5,15 @@ module Distribution.Solver.Types.SourcePackage , SourcePackage(..) ) where +import Distribution.Solver.Compat.Prelude +import Prelude () + import Distribution.Package ( PackageId, Package(..) ) import Distribution.PackageDescription ( GenericPackageDescription(..) ) import Data.ByteString.Lazy (ByteString) -import GHC.Generics (Generic) -import Distribution.Compat.Binary (Binary) -import Data.Typeable -import Distribution.Utils.Structured (Structured) -- | A package description along with the location of the package sources. -- diff --git a/cabal-install/Distribution/Solver/Types/Variable.hs b/cabal-install/Distribution/Solver/Types/Variable.hs index b4e4b1d7549..80f9de52deb 100644 --- a/cabal-install/Distribution/Solver/Types/Variable.hs +++ b/cabal-install/Distribution/Solver/Types/Variable.hs @@ -1,5 +1,7 @@ module Distribution.Solver.Types.Variable where +import Prelude (Eq, Show) + import Distribution.Solver.Types.OptionalStanza import Distribution.PackageDescription (FlagName) diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 6bdae63a749..6c17dad2065 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -163,15 +163,13 @@ import qualified Paths_cabal_install (version) import Distribution.Compat.ResponseFile import System.Environment (getArgs, getProgName) -import System.Exit (exitFailure, exitSuccess) import System.FilePath ( dropExtension, splitExtension , takeExtension, (), (<.>) ) import System.IO ( BufferMode(LineBuffering), hSetBuffering , stderr, stdout ) import System.Directory (doesFileExist, getCurrentDirectory) import Data.Monoid (Any(..)) -import Control.Exception (SomeException(..), try) -import Control.Monad (mapM_) +import Control.Exception (try) import Data.Version (showVersion) -- | Entry point @@ -978,16 +976,16 @@ execAction execFlags extraArgs globalFlags = do userConfigAction :: UserConfigFlags -> [String] -> Action userConfigAction ucflags extraArgs globalFlags = do let verbosity = fromFlag (userConfigVerbosity ucflags) - force = fromFlag (userConfigForce ucflags) + frc = fromFlag (userConfigForce ucflags) extraLines = fromFlag (userConfigAppendLines ucflags) case extraArgs of ("init":_) -> do path <- configFile fileExists <- doesFileExist path - if (not fileExists || (fileExists && force)) + if (not fileExists || (fileExists && frc)) then void $ createDefaultConfigFile verbosity extraLines path else die' verbosity $ path ++ " already exists." - ("diff":_) -> mapM_ putStrLn =<< userConfigDiff verbosity globalFlags extraLines + ("diff":_) -> traverse_ putStrLn =<< userConfigDiff verbosity globalFlags extraLines ("update":_) -> userConfigUpdate verbosity globalFlags extraLines -- Error handling. [] -> die' verbosity $ "Please specify a subcommand (see 'help user-config')" diff --git a/cabal-install/solver-dsl/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/solver-dsl/UnitTests/Distribution/Solver/Modular/DSL.hs index ed1e7ec10bd..440b8e970e2 100644 --- a/cabal-install/solver-dsl/UnitTests/Distribution/Solver/Modular/DSL.hs +++ b/cabal-install/solver-dsl/UnitTests/Distribution/Solver/Modular/DSL.hs @@ -44,7 +44,6 @@ import Distribution.Utils.Generic -- base import Control.Arrow (second) -import Data.Either (partitionEithers) import qualified Data.Map as Map -- Cabal diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index ce3f614ff8c..0ca3d80eb33 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -51,7 +51,6 @@ import Distribution.Simple.Compiler import Distribution.System import Distribution.Version import Distribution.ModuleName (ModuleName) -import Distribution.Verbosity import Distribution.Text import qualified Data.Map as Map diff --git a/cabal-install/tests/UnitTests/Distribution/Client/DescribedInstances.hs b/cabal-install/tests/UnitTests/Distribution/Client/DescribedInstances.hs index 3f8aa01a3eb..15ad5afc2f8 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/DescribedInstances.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/DescribedInstances.hs @@ -5,7 +5,6 @@ module UnitTests.Distribution.Client.DescribedInstances where import Distribution.Client.Compat.Prelude import Distribution.Described -import Distribution.Pretty (prettyShow) import Data.List ((\\)) import Distribution.Types.Dependency (Dependency) diff --git a/cabal-install/tests/UnitTests/Distribution/Client/GZipUtils.hs b/cabal-install/tests/UnitTests/Distribution/Client/GZipUtils.hs index 7139eedc45d..f2ddce463a3 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/GZipUtils.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/GZipUtils.hs @@ -7,8 +7,7 @@ import Distribution.Client.Compat.Prelude import Codec.Compression.GZip as GZip import Codec.Compression.Zlib as Zlib -import Control.Exception.Base (evaluate) -import Control.Exception (try, SomeException) +import Control.Exception (try) import Data.ByteString as BS (null) import Data.ByteString.Lazy as BSL (pack, toChunks) import Data.ByteString.Lazy.Char8 as BSLL (pack, init, length) diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Glob.hs b/cabal-install/tests/UnitTests/Distribution/Client/Glob.hs index 2762b241687..427516e332d 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Glob.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Glob.hs @@ -6,9 +6,6 @@ module UnitTests.Distribution.Client.Glob (tests) where import Distribution.Client.Compat.Prelude hiding (last) import Prelude () -import Distribution.Pretty (prettyShow) -import Distribution.Parsec (eitherParsec) - import Distribution.Client.Glob import Distribution.Utils.Structured (structureHash) import UnitTests.Distribution.Client.ArbitraryInstances () @@ -16,7 +13,6 @@ import UnitTests.Distribution.Client.ArbitraryInstances () import Test.Tasty import Test.Tasty.QuickCheck import Test.Tasty.HUnit -import Control.Exception import GHC.Fingerprint (Fingerprint (..)) tests :: [TestTree] diff --git a/cabal-install/tests/UnitTests/Distribution/Client/InstallPlan.hs b/cabal-install/tests/UnitTests/Distribution/Client/InstallPlan.hs index 3c7efae39f2..1315d2c3695 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/InstallPlan.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/InstallPlan.hs @@ -3,6 +3,9 @@ {-# LANGUAGE ConstraintKinds #-} module UnitTests.Distribution.Client.InstallPlan (tests) where +import Distribution.Client.Compat.Prelude +import qualified Prelude as Unsafe (tail) + import Distribution.Package import Distribution.Version import qualified Distribution.Client.InstallPlan as InstallPlan @@ -17,12 +20,11 @@ import Distribution.Client.JobControl import Data.Graph import Data.Array hiding (index) -import Data.List +import Data.List () +import Control.Monad (replicateM) import qualified Data.Map as Map import qualified Data.Set as Set -import Data.Set (Set) import Data.IORef -import Control.Monad import Control.Concurrent (threadDelay) import System.Random import Test.QuickCheck @@ -216,19 +218,19 @@ arbitraryInstallPlan mkIPkg mkSrcPkg ipkgProportion graph = do (ipkgvs, srcpkgvs) <- fmap ((\(ipkgs, srcpkgs) -> (map fst ipkgs, map fst srcpkgs)) . partition snd) $ - sequence + sequenceA [ do isipkg <- if isRoot then pick ipkgProportion else return False return (v, isipkg) | (v,n) <- assocs (outdegree graph) , let isRoot = n == 0 ] - ipkgs <- sequence + ipkgs <- sequenceA [ mkIPkg pkgv depvs | pkgv <- ipkgvs , let depvs = graph ! pkgv ] - srcpkgs <- sequence + srcpkgs <- sequenceA [ mkSrcPkg pkgv depvs | pkgv <- srcpkgvs , let depvs = graph ! pkgv @@ -256,9 +258,9 @@ arbitraryAcyclicGraph genNRanks genNPerRank edgeChance = do nranks <- genNRanks rankSizes <- replicateM nranks genNPerRank let rankStarts = scanl (+) 0 rankSizes - rankRanges = drop 1 (zip rankStarts (tail rankStarts)) + rankRanges = drop 1 (zip rankStarts (Unsafe.tail rankStarts)) totalRange = sum rankSizes - rankEdges <- mapM (uncurry genRank) rankRanges + rankEdges <- traverse (uncurry genRank) rankRanges return $ buildG (0, totalRange-1) (concat rankEdges) where genRank :: Vertex -> Vertex -> Gen [Edge] diff --git a/cabal-install/tests/UnitTests/Distribution/Client/JobControl.hs b/cabal-install/tests/UnitTests/Distribution/Client/JobControl.hs index 56f2e2b2083..05250ff180c 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/JobControl.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/JobControl.hs @@ -3,13 +3,13 @@ module UnitTests.Distribution.Client.JobControl (tests) where import Distribution.Client.JobControl -import Data.List -import Data.Maybe -import Data.IORef -import Control.Monad +import Distribution.Client.Compat.Prelude +import Prelude () + +import Data.IORef (newIORef, atomicModifyIORef) +import Control.Monad (replicateM_, replicateM) import Control.Concurrent (threadDelay) -import Control.Exception (Exception, try, throwIO) -import Data.Typeable (Typeable) +import Control.Exception (try) import qualified Data.Set as Set import Test.Tasty @@ -75,13 +75,13 @@ prop_interleaved_parallel (Positive (Small maxJobLimit)) xs = prop_submit :: JobControl IO Int -> [Int] -> IO Bool prop_submit jobCtl xs = do - mapM_ (\x -> spawnJob jobCtl (return x)) xs - xs' <- mapM (\_ -> collectJob jobCtl) xs + traverse_ (\x -> spawnJob jobCtl (return x)) xs + xs' <- traverse (\_ -> collectJob jobCtl) xs return (sort xs == sort xs') prop_remaining :: JobControl IO Int -> [Int] -> IO Bool prop_remaining jobCtl xs = do - mapM_ (\x -> spawnJob jobCtl (return x)) xs + traverse_ (\x -> spawnJob jobCtl (return x)) xs xs' <- collectRemainingJobs jobCtl return (sort xs == sort xs') @@ -97,7 +97,7 @@ collectRemainingJobs jobCtl = go [] prop_submit_interleaved :: JobControl IO (Maybe Int) -> [Int] -> IO Bool prop_submit_interleaved jobCtl xs = do - xs' <- sequence + xs' <- sequenceA [ spawn >> collect | let spawns = map (\x -> spawnJob jobCtl (return (Just x))) xs ++ repeat (return ()) @@ -148,8 +148,8 @@ prop_cancel_serial :: [Int] -> [Int] -> Property prop_cancel_serial xs ys = ioProperty $ do jobCtl <- newSerialJobControl - mapM_ (\x -> spawnJob jobCtl (return x)) (xs++ys) - xs' <- mapM (\_ -> collectJob jobCtl) xs + traverse_ (\x -> spawnJob jobCtl (return x)) (xs++ys) + xs' <- traverse (\_ -> collectJob jobCtl) xs cancelJobs jobCtl ys' <- collectRemainingJobs jobCtl return (sort xs == sort xs' && null ys') @@ -158,8 +158,8 @@ prop_cancel_parallel :: Positive (Small Int) -> [Int] -> [Int] -> Property prop_cancel_parallel (Positive (Small maxJobLimit)) xs ys = do ioProperty $ do jobCtl <- newParallelJobControl maxJobLimit - mapM_ (\x -> spawnJob jobCtl (threadDelay 100 >> return x)) (xs++ys) - xs' <- mapM (\_ -> collectJob jobCtl) xs + traverse_ (\x -> spawnJob jobCtl (threadDelay 100 >> return x)) (xs++ys) + xs' <- traverse (\_ -> collectJob jobCtl) xs cancelJobs jobCtl ys' <- collectRemainingJobs jobCtl return $ Set.fromList (xs'++ys') `Set.isSubsetOf` Set.fromList (xs++ys) @@ -183,7 +183,7 @@ prop_exception_parallel (Positive (Small maxJobLimit)) xs = prop_exception :: JobControl IO Int -> [Either Int Int] -> IO Bool prop_exception jobCtl xs = do - mapM_ (\x -> spawnJob jobCtl (either (throwIO . TestException) return x)) xs + traverse_ (\x -> spawnJob jobCtl (either (throwIO . TestException) return x)) xs xs' <- replicateM (length xs) $ do mx <- try (collectJob jobCtl) return $ case mx of diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs index 6135f571951..e535e73fce4 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs @@ -31,7 +31,6 @@ import Prelude () import Distribution.Solver.Compat.Prelude import Data.List (elemIndex) -import Data.Ord (comparing) -- test-framework import Test.Tasty as TF diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs index a1a6412d014..3aa4b54c443 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs @@ -9,12 +9,9 @@ import Prelude () import Distribution.Client.Compat.Prelude import Control.Arrow ((&&&)) -import Control.DeepSeq (force) import Data.Either (lefts) -import Data.Function (on) import Data.Hashable (Hashable(..)) import Data.List (groupBy, isInfixOf) -import Data.Ord (comparing) import Text.Show.Pretty (parseValue, valToStr)