Optimise Digraph.postOrd, used when finding strongly connected components
[ghc-hetmet.git] / compiler / utils / Util.lhs
index bfb499a..e5f7023 100644 (file)
@@ -26,7 +26,7 @@ module Util (
        nTimes,
 
        -- sorting
-       sortLe, sortWith,
+       sortLe, sortWith, on,
 
        -- transitive closures
        transitiveClosure,
@@ -457,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}
 
 %************************************************************************
@@ -590,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