[project @ 2002-05-01 09:30:04 by simonmar]
[ghc-hetmet.git] / ghc / compiler / utils / Util.lhs
index 8c86eea..a8d289d 100644 (file)
@@ -20,15 +20,14 @@ module Util (
        nOfThem, 
        lengthExceeds, lengthIs, lengthAtLeast, listLengthCmp, atLength,
        isSingleton, only,
+       notNull,
+
        snocView,
        isIn, isn'tIn,
 
        -- for-loop
        nTimes,
 
-       -- maybe-ish
-       unJust,
-
        -- sorting
        IF_NOT_GHC(quicksort COMMA stableSortLt COMMA mergesort COMMA)
        sortLt,
@@ -133,18 +132,6 @@ nTimes n f = f . nTimes (n-1) f
 
 %************************************************************************
 %*                                                                     *
-\subsection{Maybe-ery}
-%*                                                                     *
-%************************************************************************
-
-\begin{code}
-unJust :: String -> Maybe a -> a
-unJust who (Just x) = x
-unJust who Nothing  = panic ("unJust of Nothing, called by " ++ who)
-\end{code}
-
-%************************************************************************
-%*                                                                     *
 \subsection[Utils-lists]{General list processing}
 %*                                                                     *
 %************************************************************************
@@ -257,10 +244,11 @@ atLength atLenPred atEndPred ls n
 
 -- special cases.
 lengthExceeds :: [a] -> Int -> Bool
-lengthExceeds = atLength (not.null) (const False)
+-- (lengthExceeds xs n) = (length xs > n)
+lengthExceeds = atLength notNull (const False)
 
 lengthAtLeast :: [a] -> Int -> Bool
-lengthAtLeast = atLength (not.null) (== 0)
+lengthAtLeast = atLength notNull (== 0)
 
 lengthIs :: [a] -> Int -> Bool
 lengthIs = atLength null (==0)
@@ -280,6 +268,10 @@ isSingleton :: [a] -> Bool
 isSingleton [x] = True
 isSingleton  _  = False
 
+notNull :: [a] -> Bool
+notNull [] = False
+notNull _  = True
+
 only :: [a] -> a
 #ifdef DEBUG
 only [a] = a