Commit 62e54ca4 authored by Simon Marlow's avatar Simon Marlow
Browse files

Avoid use of deprecated Data.FiniteMap, if possible

Distribution.Compat.Map taken from Haddock.
parent a7b22cc8
......@@ -49,6 +49,7 @@ Exposed-Modules:
Distribution.Version,
Language.Haskell.Extension,
Distribution.GetOpt,
Distribution.Compat.Map,
Distribution.Compat.Directory,
Distribution.Compat.Exception,
Distribution.Compat.FilePath,
......
module Distribution.Compat.Map (
Map,
member, lookup, findWithDefault,
empty,
insert, insertWith,
union, unionWith, unions,
elems, keys,
fromList, fromListWith,
toAscList
) where
import Prelude hiding ( lookup )
#if __GLASGOW_HASKELL__ >= 603
import Data.Map
#else
import Data.FiniteMap
type Map k a = FiniteMap k a
instance Functor (FiniteMap k) where
fmap f = mapFM (const f)
member :: Ord k => k -> Map k a -> Bool
member = elemFM
lookup :: Ord k => k -> Map k a -> Maybe a
lookup = flip lookupFM
findWithDefault :: Ord k => a -> k -> Map k a -> a
findWithDefault a k m = lookupWithDefaultFM m a k
empty :: Map k a
empty = emptyFM
insert :: Ord k => k -> a -> Map k a -> Map k a
insert k a m = addToFM m k a
insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
insertWith c k a m = addToFM_C (flip c) m k a
union :: Ord k => Map k a -> Map k a -> Map k a
union = flip plusFM
unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
unionWith c l r = plusFM_C (flip c) r l
unions :: Ord k => [Map k a] -> Map k a
unions = foldl (flip plusFM) emptyFM
elems :: Map k a -> [a]
elems = eltsFM
keys :: Map k a -> [k]
keys = keysFM
fromList :: Ord k => [(k,a)] -> Map k a
fromList = listToFM
fromListWith :: Ord k => (a -> a -> a) -> [(k,a)] -> Map k a
fromListWith c = addListToFM_C (flip c) emptyFM
toAscList :: Map k a -> [(k,a)]
toAscList = fmToList
#endif
......@@ -32,7 +32,7 @@ module Distribution.Program( Program(..)
, pfesetupProgram
) where
import Data.FiniteMap
import qualified Distribution.Compat.Map as Map
import Control.Monad(when)
import Data.Maybe(catMaybes)
import System.Exit (ExitCode)
......@@ -58,15 +58,15 @@ data ProgramLocation = EmptyLocation
| FoundOnSystem FilePath
deriving (Read, Show)
data ProgramConfiguration = ProgramConfiguration (FiniteMap String Program)
data ProgramConfiguration = ProgramConfiguration (Map.Map String Program)
-- Read & Show instances are based on listToFM
instance Show ProgramConfiguration where
show (ProgramConfiguration s) = show $ fmToList s
show (ProgramConfiguration s) = show $ Map.toAscList s
instance Read ProgramConfiguration where
readsPrec p s = [(ProgramConfiguration $ listToFM $ s', r)
readsPrec p s = [(ProgramConfiguration $ Map.fromList $ s', r)
| (s', r) <- readsPrec p s ]
-- |The default list of programs and their arguments. These programs
......@@ -191,7 +191,7 @@ lookupProgram name conf =
lookupPrograms :: ProgramConfiguration -> IO [(String, Maybe Program)]
lookupPrograms conf@(ProgramConfiguration fm) = do
let l = eltsFM fm
let l = Map.elems fm
mapM (\p -> do fp <- lookupProgram (programName p) conf
return (programName p, fp)
) l
......@@ -204,7 +204,7 @@ userSpecifyPath :: String -- ^Program name
-> ProgramConfiguration
-> ProgramConfiguration
userSpecifyPath name path conf'@(ProgramConfiguration conf)
= case lookupFM conf name of
= case Map.lookup name conf of
Just p -> updateProgram (Just p{programLocation=UserSpecified path}) conf'
Nothing -> updateProgram (Just $ Program name name [] (UserSpecified path))
conf'
......@@ -217,7 +217,7 @@ userSpecifyArgs :: String -- ^Program name
-> ProgramConfiguration
-> ProgramConfiguration
userSpecifyArgs name args conf'@(ProgramConfiguration conf)
= case lookupFM conf name of
= case Map.lookup name conf of
Just p -> updateProgram (Just p{programArgs=(words args)}) conf'
Nothing -> updateProgram (Just $ Program name name (words args) EmptyLocation) conf'
......@@ -225,7 +225,7 @@ userSpecifyArgs name args conf'@(ProgramConfiguration conf)
-- you pass in Nothing.
updateProgram :: Maybe Program -> ProgramConfiguration -> ProgramConfiguration
updateProgram (Just p@Program{programName=n}) (ProgramConfiguration conf)
= ProgramConfiguration $ addToFM conf n p
= ProgramConfiguration $ Map.insert n p conf
updateProgram Nothing conf = conf
-- |Runs the given program.
......@@ -266,14 +266,14 @@ rawSystemProgramConf verbose progName programConf extraArgs
-- Export?
lookupProgram' :: String -> ProgramConfiguration -> Maybe Program
lookupProgram' s (ProgramConfiguration conf) = lookupFM conf s
lookupProgram' s (ProgramConfiguration conf) = Map.lookup s conf
progListToFM :: [Program] -> ProgramConfiguration
progListToFM progs = foldl
(\ (ProgramConfiguration conf')
p@(Program {programName=n})
-> ProgramConfiguration (addToFM conf' n p))
(ProgramConfiguration emptyFM)
-> ProgramConfiguration (Map.insert n p conf'))
(ProgramConfiguration Map.empty)
progs
simpleProgram :: String -> Program
......
......@@ -73,7 +73,7 @@ import Distribution.Simple.Utils (die)
import Distribution.Program(ProgramConfiguration(..),
userSpecifyPath, userSpecifyArgs)
import Data.List(find)
import Data.FiniteMap(keysFM)
import Distribution.Compat.Map (keys)
import Distribution.GetOpt
import Distribution.Compat.FilePath (platformPath)
import System.Exit
......@@ -470,12 +470,12 @@ configureCmd progConf = Cmd {
}
programArgsOptions :: ProgramConfiguration -> [OptDescr (Flag a)]
programArgsOptions (ProgramConfiguration conf) = map f (keysFM conf)
programArgsOptions (ProgramConfiguration conf) = map f (keys conf)
where f name = Option "" [name ++ "-args"] (reqPathArg (ProgramArgs name))
("give the args to " ++ name)
withProgramOptions :: ProgramConfiguration -> [OptDescr (Flag a)]
withProgramOptions (ProgramConfiguration conf) = map f (keysFM conf)
withProgramOptions (ProgramConfiguration conf) = map f (keys conf)
where f name = Option "" ["with-" ++ name] (reqPathArg (WithProgram name))
("give the path to " ++ name)
......
......@@ -40,6 +40,7 @@ exposed-modules:
hidden-modules:
Distribution.GetOpt,
Distribution.Compat.Map,
Distribution.Compat.Exception,
Distribution.Compat.RawSystem,
Distribution.Compat.FilePath,
......
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