Remove maybePrefixMatch, using stripPrefix instead
authorIan Lynagh <igloo@earth.li>
Thu, 9 Jul 2009 16:04:12 +0000 (16:04 +0000)
committerIan Lynagh <igloo@earth.li>
Thu, 9 Jul 2009 16:04:12 +0000 (16:04 +0000)
We already require GHC 6.8 to build, and that included stripPrefix
in Data.List.

compiler/main/CmdLineParser.hs
compiler/main/DynFlags.hs
compiler/main/Packages.lhs
compiler/main/StaticFlags.hs
compiler/parser/Lexer.x
compiler/utils/Util.lhs

index dfdea62..dfe756b 100644 (file)
@@ -23,6 +23,8 @@ import Outputable
 import Panic
 import SrcLoc
 
+import Data.List
+
 data Flag m = Flag
     {
         flagName :: String,           -- flag, without the leading -
@@ -118,7 +120,7 @@ findArg spec arg
   = case [ (removeSpaces rest, optKind, flagDeprecated flag)
          | flag <- spec,
            let optKind = flagOptKind flag,
-           Just rest <- [maybePrefixMatch (flagName flag) arg],
+           Just rest <- [stripPrefix (flagName flag) arg],
            arg_ok optKind rest arg ]
     of
         []      -> Nothing
index e39bff3..bebea76 100644 (file)
@@ -92,7 +92,7 @@ import Data.IORef
 import Control.Monad    ( when )
 
 import Data.Char
-import Data.List        ( intersperse )
+import Data.List
 import System.FilePath
 import System.IO        ( stderr, hPutChar )
 
@@ -826,7 +826,7 @@ addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d }
 -- We used to use "-optdep-flag -optdeparg", so for legacy applications
 -- we need to strip the "-optdep" off of the arg
 deOptDep :: String -> String
-deOptDep x = case maybePrefixMatch "-optdep" x of
+deOptDep x = case stripPrefix "-optdep" x of
              Just rest -> rest
              Nothing -> x
 
index 505a797..bdb8cf7 100644 (file)
@@ -265,8 +265,8 @@ mungePackagePaths top_dir ps = map munge_pkg ps
   munge_paths = map munge_path
 
   munge_path p 
-         | Just p' <- maybePrefixMatch "$topdir"     p =            top_dir ++ p'
-         | Just p' <- maybePrefixMatch "$httptopdir" p = toHttpPath top_dir ++ p'
+         | Just p' <- stripPrefix "$topdir"     p =            top_dir ++ p'
+         | Just p' <- stripPrefix "$httptopdir" p = toHttpPath top_dir ++ p'
          | otherwise                               = p
 
   toHttpPath p = "file:///" ++ p
index 3660d37..126b3a0 100644 (file)
@@ -134,7 +134,7 @@ lookUp     sw = sw `elem` packed_static_opts
 -- (lookup_str "foo") looks for the flag -foo=X or -fooX, 
 -- and returns the string X
 lookup_str sw 
-   = case firstJust (map (maybePrefixMatch sw) staticFlags) of
+   = case firstJust (map (stripPrefix sw) staticFlags) of
        Just ('=' : str) -> Just str
        Just str         -> Just str
        Nothing          -> Nothing     
index fb7a535..ffabc61 100644 (file)
@@ -65,7 +65,7 @@ import SrcLoc
 import UniqFM
 import DynFlags
 import Ctype
-import Util            ( maybePrefixMatch, readRational )
+import Util            ( readRational )
 
 import Control.Monad
 import Data.Bits
@@ -1323,7 +1323,7 @@ lex_escape = do
                Just (c3,i3) -> 
                   let str = [c1,c2,c3] in
                   case [ (c,rest) | (p,c) <- silly_escape_chars,
-                                    Just rest <- [maybePrefixMatch p str] ] of
+                                    Just rest <- [stripPrefix p str] ] of
                          (escape_char,[]):_ -> do
                                setInput i3
                                return escape_char
index 62ab5f9..3de52b6 100644 (file)
@@ -42,7 +42,7 @@ module Util (
 
         -- * Comparisons
         isEqual, eqListBy,
-        thenCmp, cmpList, maybePrefixMatch,
+        thenCmp, cmpList,
         removeSpaces,
 
         -- * Transitive closures
@@ -664,15 +664,6 @@ cmpList cmp (a:as) (b:bs)
 \end{code}
 
 \begin{code}
--- This (with a more general type) is Data.List.stripPrefix from GHC 6.8.
--- This definition can be removed once we require at least 6.8 to build.
-maybePrefixMatch :: String -> String -> Maybe String
-maybePrefixMatch []    rest = Just rest
-maybePrefixMatch (_:_) []   = Nothing
-maybePrefixMatch (p:pat) (r:rest)
-  | p == r    = maybePrefixMatch pat rest
-  | otherwise = Nothing
-
 removeSpaces :: String -> String
 removeSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace
 \end{code}