X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FUtil.lhs;h=e5f702355244f20521c63c1ddbb27f84aba924d6;hb=f0d0e9d63ee27a12e80b6f069be5e9d4b55ca545;hp=8473faf42eeb94d29641c35e850b2e5d7a9454d7;hpb=8100c58a929d993d2dd7022412ed6113cf97fba7;p=ghc-hetmet.git diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs index 8473faf..e5f7023 100644 --- a/compiler/utils/Util.lhs +++ b/compiler/utils/Util.lhs @@ -26,7 +26,7 @@ module Util ( nTimes, -- sorting - sortLe, sortWith, + sortLe, sortWith, on, -- transitive closures transitiveClosure, @@ -79,9 +79,12 @@ module Util ( #include "HsVersions.h" -import Panic ( panic, trace ) import FastTypes +#ifdef DEBUG +import Panic ( panic, trace ) +#endif + import Control.Exception ( Exception(..), finally, catchDyn, throw ) import qualified Control.Exception as Exception import Data.Dynamic ( Typeable ) @@ -89,10 +92,11 @@ import Data.IORef ( IORef, newIORef ) import System.IO.Unsafe ( unsafePerformIO ) import Data.IORef ( readIORef, writeIORef ) -import qualified Data.List as List ( elem, notElem ) - +import qualified Data.List as List ( elem ) #ifndef DEBUG import Data.List ( zipWith4 ) +#else +import qualified Data.List as List ( notElem ) #endif import Control.Monad ( when ) @@ -453,6 +457,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 + +on :: (a -> a -> Ordering) -> (b -> a) -> b -> b -> Ordering +on cmp sel = \x y -> sel x `cmp` sel y + \end{code} %************************************************************************ @@ -586,6 +594,8 @@ 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