Skip to content
Snippets Groups Projects
Commit 4211484b authored by Simon Marlow's avatar Simon Marlow
Browse files

[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
parent 60bf7108
No related branches found
No related tags found
No related merge requests found
......@@ -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}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment