[project @ 1996-05-01 18:36:59 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / Util.lhs
index 2aaec61..c6e92c0 100644 (file)
@@ -39,6 +39,7 @@ module Util (
        IF_NOT_GHC(forall COMMA exists COMMA)
        zipEqual, zipWithEqual, zipWith3Equal, zipWith4Equal,
         zipLazy,
+       mapAndUnzip,
        nOfThem, lengthExceeds, isSingleton,
        startsWith, endsWith,
 #if defined(COMPILING_GHC)
@@ -79,9 +80,7 @@ module Util (
        -- error handling
 #if defined(COMPILING_GHC)
        , panic, panic#, pprPanic, pprPanic#, pprError, pprTrace
-# ifdef DEBUG
        , assertPanic
-# endif
 #endif {- COMPILING_GHC -}
 
        -- and to make the interface self-sufficient...
@@ -185,6 +184,18 @@ zipLazy (x:xs) ~(y:ys) = (x,y) : zipLazy xs ys
 \end{code}
 
 \begin{code}
+mapAndUnzip :: (a -> (b, c)) -> [a] -> ([b], [c])
+
+mapAndUnzip f [] = ([],[])
+mapAndUnzip f (x:xs)
+  = let
+       (r1,  r2)  = f x
+       (rs1, rs2) = mapAndUnzip f xs
+    in
+    (r1:rs1, r2:rs2)
+\end{code}
+
+\begin{code}
 nOfThem :: Int -> a -> [a]
 nOfThem n thing = take n (repeat thing)
 
@@ -245,27 +256,6 @@ isn'tIn msg x ys
 
 # endif {- DEBUG -}
 
-# ifdef USE_ATTACK_PRAGMAS
-{-# SPECIALIZE isIn :: String -> Literal -> [Literal] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> Class -> [Class] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> Id -> [Id] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> Int -> [Int] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> MagicId -> [MagicId] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> Name -> [Name] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> TyCon -> [TyCon] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> TyVar -> [TyVar] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> TyVarTemplate -> [TyVarTemplate] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> Unique -> [Unique] -> Bool #-}
-{-# SPECIALIZE isIn :: String -> _PackedString -> [_PackedString] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> (Id, Id) -> [(Id, Id)] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> Int -> [Int] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> Id -> [Id] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> MagicId -> [MagicId] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> TyCon -> [TyCon] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> TyVar -> [TyVar] -> Bool #-}
-{-# SPECIALIZE isn'tIn :: String -> TyVarTemplate -> [TyVarTemplate] -> Bool #-}
-# endif
-
 #endif {- COMPILING_GHC -}
 \end{code}
 
@@ -285,21 +275,6 @@ assoc crash_msg lst key
     then panic ("Failed in assoc: " ++ crash_msg)
     else head res
   where res = [ val | (key', val) <- lst, key == key']
-
-#if defined(COMPILING_GHC)
-# ifdef USE_ATTACK_PRAGMAS
-{-# SPECIALIZE assoc :: String -> [(Id,            a)] -> Id           -> a #-}
-{-# SPECIALIZE assoc :: String -> [(Class,         a)] -> Class                -> a #-}
-{-# SPECIALIZE assoc :: String -> [(Name,          a)] -> Name         -> a #-}
-{-# SPECIALIZE assoc :: String -> [(PrimRep,      a)] -> PrimRep       -> a #-}
-{-# SPECIALIZE assoc :: String -> [(String,        a)] -> String        -> a #-}
-{-# SPECIALIZE assoc :: String -> [(TyCon,         a)] -> TyCon                -> a #-}
-{-# SPECIALIZE assoc :: String -> [(TyVar,         a)] -> TyVar                -> a #-}
-{-# SPECIALIZE assoc :: String -> [(TyVarTemplate, a)] -> TyVarTemplate -> a #-}
-{-# SPECIALIZE assoc :: String -> [(Type,          a)] -> Type         -> a #-}
-{-# SPECIALIZE assoc :: String -> [(_PackedString, a)] -> _PackedString -> a #-}
-# endif
-#endif
 \end{code}
 
 %************************************************************************
@@ -324,11 +299,6 @@ hasNoDups xs = f [] xs
 #else
     is_elem = elem
 #endif
-#if defined(COMPILING_GHC)
-# ifdef USE_ATTACK_PRAGMAS
-{-# SPECIALIZE hasNoDups :: [TyVar] -> Bool #-}
-# endif
-#endif
 \end{code}
 
 \begin{code}
@@ -831,9 +801,8 @@ panic# s = case (panic s) of () -> EQ_
 
 pprPanic# heading pretty_msg = panic# (heading++(ppShow 80 pretty_msg))
 
-# ifdef DEBUG
 assertPanic :: String -> Int -> a
 assertPanic file line = panic ("ASSERT failed! file "++file++", line "++show line)
-# endif
+
 #endif {- COMPILING_GHC -}
 \end{code}