projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
catch up with changes to checkModule
[ghc-hetmet.git]
/
compiler
/
utils
/
Util.lhs
diff --git
a/compiler/utils/Util.lhs
b/compiler/utils/Util.lhs
index
bfb499a
..
6cefad6
100644
(file)
--- a/
compiler/utils/Util.lhs
+++ b/
compiler/utils/Util.lhs
@@
-5,6
+5,13
@@
\section[Util]{Highly random utility functions}
\begin{code}
\section[Util]{Highly random utility functions}
\begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
module Util (
-- general list processing
module Util (
-- general list processing
@@
-13,6
+20,7
@@
module Util (
mapFst, mapSnd,
mapAndUnzip, mapAndUnzip3,
nOfThem, filterOut, partitionWith, splitEithers,
mapFst, mapSnd,
mapAndUnzip, mapAndUnzip3,
nOfThem, filterOut, partitionWith, splitEithers,
+ foldl1',
lengthExceeds, lengthIs, lengthAtLeast,
listLengthCmp, atLength, equalLength, compareLength,
lengthExceeds, lengthIs, lengthAtLeast,
listLengthCmp, atLength, equalLength, compareLength,
@@
-26,7
+34,7
@@
module Util (
nTimes,
-- sorting
nTimes,
-- sorting
- sortLe, sortWith,
+ sortLe, sortWith, on,
-- transitive closures
transitiveClosure,
-- transitive closures
transitiveClosure,
@@
-81,8
+89,8
@@
module Util (
import FastTypes
import FastTypes
-#ifdef DEBUG
-import Panic ( panic, trace )
+#if defined(DEBUG) || __GLASGOW_HASKELL__ < 604
+import Panic
#endif
import Control.Exception ( Exception(..), finally, catchDyn, throw )
#endif
import Control.Exception ( Exception(..), finally, catchDyn, throw )
@@
-91,11
+99,10
@@
import Data.Dynamic ( Typeable )
import Data.IORef ( IORef, newIORef )
import System.IO.Unsafe ( unsafePerformIO )
import Data.IORef ( readIORef, writeIORef )
import Data.IORef ( IORef, newIORef )
import System.IO.Unsafe ( unsafePerformIO )
import Data.IORef ( readIORef, writeIORef )
+import Data.List hiding (group)
import qualified Data.List as List ( elem )
import qualified Data.List as List ( elem )
-#ifndef DEBUG
-import Data.List ( zipWith4 )
-#else
+#ifdef DEBUG
import qualified Data.List as List ( notElem )
#endif
import qualified Data.List as List ( notElem )
#endif
@@
-356,6
+363,16
@@
isn'tIn msg x ys
# endif /* DEBUG */
\end{code}
# endif /* DEBUG */
\end{code}
+foldl1' was added in GHC 6.4
+
+\begin{code}
+#if __GLASGOW_HASKELL__ < 604
+foldl1' :: (a -> a -> a) -> [a] -> a
+foldl1' f (x:xs) = foldl' f x xs
+foldl1' _ [] = panic "foldl1'"
+#endif
+\end{code}
+
%************************************************************************
%* *
\subsubsection[Utils-Carsten-mergesort]{A mergesort from Carsten}
%************************************************************************
%* *
\subsubsection[Utils-Carsten-mergesort]{A mergesort from Carsten}
@@
-457,6
+474,10
@@
sortWith :: Ord b => (a->b) -> [a] -> [a]
sortWith get_key xs = sortLe le xs
where
x `le` y = get_key x < get_key y
sortWith get_key xs = sortLe le xs
where
x `le` y = get_key x < get_key y
+
+on :: (a -> a -> Ordering) -> (b -> a) -> b -> b -> Ordering
+on cmp sel = \x y -> sel x `cmp` sel y
+
\end{code}
%************************************************************************
\end{code}
%************************************************************************
@@
-590,6
+611,8
@@
cmpList cmp (a:as) (b:bs)
\end{code}
\begin{code}
\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 :: String -> String -> Maybe String
maybePrefixMatch [] rest = Just rest
maybePrefixMatch (_:_) [] = Nothing