Skip to content

Commit

Permalink
Merge pull request #6456 from phadej/issue-6375
Browse files Browse the repository at this point in the history
Resolve #6375: Let export safe* from both Utils.Generic and Simple.Utils
  • Loading branch information
phadej authored Dec 23, 2019
2 parents 0dda5b9 + a247dcf commit 8c18ad5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Distribution.Types.CondTree
import Distribution.Types.ExeDependency
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName
import Distribution.Utils.Generic (isAscii, safeInit)
import Distribution.Utils.Generic (isAscii)
import Distribution.Verbosity
import Distribution.Version
import Language.Haskell.Extension
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module Distribution.Simple.Compiler (

import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Utils.Generic(safeLast)
import Distribution.Pretty

import Distribution.Compiler
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import Distribution.Backpack.DescribeUnitId
import Distribution.Backpack.PreExistingComponent
import Distribution.Backpack.ConfiguredComponent (newPackageDepsBehaviour)
import Distribution.Backpack.Id
import Distribution.Utils.Generic
import Distribution.Utils.LogProgress

import qualified Distribution.Simple.GHC as GHC
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/HaskellSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import Distribution.System (Platform)
import Distribution.Compat.Exception
import Distribution.Utils.Generic
import Language.Haskell.Extension
import Distribution.Simple.Program.Builtin

Expand Down
2 changes: 2 additions & 0 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ module Distribution.Simple.Utils (
ordNubRight,
safeHead,
safeTail,
safeLast,
safeInit,
unintersperse,
wrapText,
wrapLine,
Expand Down
8 changes: 8 additions & 0 deletions Cabal/Distribution/Utils/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,29 @@ listUnionRight a b = ordNubRight (filter (`Set.notMember` bSet) a) ++ b
bSet = Set.fromList b

-- | A total variant of 'head'.
--
-- @since 3.2.0.0
safeHead :: [a] -> Maybe a
safeHead [] = Nothing
safeHead (x:_) = Just x

-- | A total variant of 'tail'.
--
-- @since 3.2.0.0
safeTail :: [a] -> [a]
safeTail [] = []
safeTail (_:xs) = xs

-- | A total variant of 'last'.
--
-- @since 3.2.0.0
safeLast :: [a] -> Maybe a
safeLast [] = Nothing
safeLast (x:xs) = Just (foldl (\_ a -> a) x xs)

-- | A total variant of 'init'.
--
-- @since 3.2.0.0
safeInit :: [a] -> [a]
safeInit [] = []
safeInit [_] = []
Expand Down

0 comments on commit 8c18ad5

Please sign in to comment.