[project @ 2000-10-11 13:27:35 by simonmar]
authorsimonmar <unknown>
Wed, 11 Oct 2000 13:27:35 +0000 (13:27 +0000)
committersimonmar <unknown>
Wed, 11 Oct 2000 13:27:35 +0000 (13:27 +0000)
- add prefixMatch & postfixMatch list comparison operators
- add 'global' for global vars
- remove unused cmpString
- remove unused imports

ghc/compiler/utils/Util.lhs

index 50587e2..ba730e9 100644 (file)
@@ -37,7 +37,7 @@ module Util (
        mapAccumL, mapAccumR, mapAccumB, foldl2, count,
 
        -- comparisons
-       thenCmp, cmpList,
+       thenCmp, cmpList, prefixMatch, postfixMatch,
 
        -- strictness
        seqList, ($!),
@@ -52,14 +52,15 @@ module Util (
        , bracket
 #endif
 
+       , global
+
     ) where
 
 #include "HsVersions.h"
 
 import List            ( zipWith4 )
 import Panic           ( panic )
-import Unique          ( Unique )
-import UniqFM          ( eltsUFM, emptyUFM, addToUFM_C )
+import IOExts          ( IORef, newIORef, unsafePerformIO )
 
 infixr 9 `thenCmp`
 \end{code}
@@ -622,17 +623,16 @@ cmpList cmp (a:as) (b:bs)
 \end{code}
 
 \begin{code}
-cmpString :: String -> String -> Ordering
-
-cmpString []     []    = EQ
-cmpString (x:xs) (y:ys) = if     x == y then cmpString xs ys
-                         else if x  < y then LT
-                         else                GT
-cmpString []     ys    = LT
-cmpString xs     []    = GT
+prefixMatch :: Eq a => [a] -> [a] -> Bool
+prefixMatch [] _str = True
+prefixMatch _pat [] = False
+prefixMatch (p:ps) (s:ss) | p == s    = prefixMatch ps ss
+                         | otherwise = False
+
+postfixMatch :: Eq a => [a] -> [a] -> Bool
+postfixMatch pat str = prefixMatch (reverse pat) (reverse str)
 \end{code}
 
-
 %************************************************************************
 %*                                                                     *
 \subsection[Utils-pairs]{Pairs}
@@ -695,3 +695,11 @@ bracket before after thing = do
   return r
 #endif
 \end{code}
+
+Global variables:
+
+\begin{code}
+global :: a -> IORef a
+global a = unsafePerformIO (newIORef a)
+\end{code}
+