From 4211484bbfb9aee2a1a24d893d467453a8765b43 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 11 Oct 2000 13:27:35 +0000 Subject: [PATCH] [project @ 2000-10-11 13:27:35 by simonmar] - add prefixMatch & postfixMatch list comparison operators - add 'global' for global vars - remove unused cmpString - remove unused imports --- ghc/compiler/utils/Util.lhs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/ghc/compiler/utils/Util.lhs b/ghc/compiler/utils/Util.lhs index 50587e2..ba730e9 100644 --- a/ghc/compiler/utils/Util.lhs +++ b/ghc/compiler/utils/Util.lhs @@ -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} + -- 1.7.10.4