Commit 575524f7 authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Add Distribution.Compat.Prelude, and use it in .Graph

parent ad6af39f
......@@ -378,6 +378,7 @@ library
Distribution.Compat.Binary
other-modules:
Distribution.Compat.Prelude
Distribution.Compat.CopyFile
Distribution.Compat.GetShortPathName
Distribution.Compat.MonadFail
......
......@@ -80,20 +80,18 @@ module Distribution.Compat.Graph (
nodeValue,
) where
import qualified Prelude as Prelude
import Prelude hiding (lookup, null)
import Prelude ()
import qualified Distribution.Compat.Prelude as Prelude
import Distribution.Compat.Prelude hiding (lookup, null, empty)
import Data.Graph (SCC(..))
import qualified Data.Graph as G
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Array as Array
import Data.Array ((!))
import qualified Data.Tree as Tree
import Data.Either (partitionEithers)
import Data.Typeable (Typeable)
import qualified Data.Foldable as Foldable
import Control.DeepSeq (NFData(..))
import Distribution.Compat.Binary (Binary(..))
-- | A graph of nodes @a@. The nodes are expected to have instance
-- of class 'IsNode'.
......
{-# LANGUAGE CPP #-}
#ifdef MIN_VERSION_base
#define MINVER_base_48 MIN_VERSION_base(4,8,0)
#define MINVER_base_47 MIN_VERSION_base(4,7,0)
#define MINVER_base_46 MIN_VERSION_base(4,6,0)
#else
#define MINVER_base_48 (__GLASGOW_HASKELL__ >= 710)
#define MINVER_base_47 (__GLASGOW_HASKELL__ >= 708)
#define MINVER_base_46 (__GLASGOW_HASKELL__ >= 706)
#endif
module Distribution.Compat.Prelude (
-- * Prelude
--
-- Prelude is re-exported, following is hided:
module BasePrelude,
#if !MINVER_base_48
-- * base 4.8 shim
Applicative(..), (<$), (<$>),
Monoid(..),
#endif
-- * Common type-classes
Semigroup (..),
gmappend, gmempty,
Typeable,
Data,
Generic,
NFData (..),
Binary (..),
Alternative (..),
MonadPlus (..),
-- * Some types
Map,
-- * Data.Maybe
catMaybes, mapMaybe,
fromMaybe,
maybeToList, listToMaybe,
isNothing, isJust,
-- * Data.List
unfoldr,
isPrefixOf, isSuffixOf,
intercalate, intersperse,
sort, sortBy,
nub, nubBy,
-- * Data.Foldable
Foldable, foldMap, foldr,
null, length,
find, foldl',
traverse_, for_,
-- * Data.Traversable
Traversable, traverse, sequenceA,
for,
-- * Control.Arrow
first,
-- * Control.Monad
liftM, liftM2,
unless, when,
ap, void,
foldM, filterM,
-- * Data.Char
isSpace, isDigit, isUpper, isAlpha, isAlphaNum,
chr, ord,
toLower, toUpper,
-- * Text.PrettyPrint
(<<>>),
) where
-- We also could hide few partial function
import Prelude as BasePrelude hiding
( mapM, mapM_, sequence, null, length, foldr
#if MINVER_base_48
-- We hide them, as we import only some members
, Traversable, traverse, sequenceA
, Foldable, foldMap
#endif
)
#if !MINVER_base_48
import Control.Applicative (Applicative (..), (<$), (<$>))
import Distribution.Compat.Semigroup (Monoid (..))
#else
import Data.Foldable (length, null)
#endif
import Data.Foldable (Foldable (foldMap, foldr), find, foldl', for_, traverse_)
import Data.Traversable (Traversable (traverse, sequenceA), for)
import Control.Applicative (Alternative (..))
import Control.DeepSeq (NFData (..))
import Data.Data (Data)
import Data.Typeable (Typeable)
import Distribution.Compat.Binary (Binary (..))
import Distribution.Compat.Semigroup (Semigroup (..), gmappend, gmempty)
import GHC.Generics (Generic)
import Data.Map (Map)
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.Maybe
import qualified Text.PrettyPrint as Disp
-- | New name for 'Text.PrettyPrint.<>'
(<<>>) :: Disp.Doc -> Disp.Doc -> Disp.Doc
(<<>>) = (Disp.<>)
#if !MINVER_base_48
-- | Test whether the structure is empty. The default implementation is
-- optimized for structures that are similar to cons-lists, because there
-- is no general way to do better.
null :: Foldable t => t a -> Bool
null = foldr (\_ _ -> False) True
-- | Returns the size/length of a finite structure as an 'Int'. The
-- default implementation is optimized for structures that are similar to
-- cons-lists, because there is no general way to do better.
length :: Foldable t => t a -> Int
length = foldl' (\c _ -> c+1) 0
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment