[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / Maybes.lhs
index 1465534..1f17679 100644 (file)
@@ -12,8 +12,7 @@ module Maybes (
 --     Maybe(..), -- no, it's in 1.3
        MaybeErr(..),
 
-       allMaybes,      -- GHCI only
-       catMaybes,
+       allMaybes,
        firstJust,
        expectJust,
        maybeToBool,
@@ -24,13 +23,13 @@ module Maybes (
        failMaB,
        failMaybe,
        seqMaybe,
-       mapMaybe,       -- GHCI only
        returnMaB,
-       returnMaybe,    -- GHCI only
-       thenMaB,
-       thenMaybe       -- GHCI only
+       returnMaybe,
+       thenMaB
 
-#if ! defined(COMPILING_GHC)
+#if defined(COMPILING_GHC)
+       , catMaybes
+#else
        , findJust
        , foldlMaybeErrs
        , listMaybeErrs
@@ -41,9 +40,10 @@ module Maybes (
 
 CHK_Ubiq() -- debugging consistency check
 
-#if USE_ATTACK_PRAGMAS
-import Util
-#endif
+import Unique (Unique) -- only for specialising
+
+#else
+import Maybe -- renamer will tell us if there are any conflicts
 #endif
 \end{code}
 
@@ -55,14 +55,6 @@ import Util
 %************************************************************************
 
 \begin{code}
-#if __HASKELL1__ < 3
-data Maybe a
-  = Nothing
-  | Just a
-#endif
-\end{code}
-
-\begin{code}
 maybeToBool :: Maybe a -> Bool
 maybeToBool Nothing  = False
 maybeToBool (Just x) = True
@@ -74,10 +66,12 @@ a list of @Justs@ into a single @Just@, returning @Nothing@ if there
 are any @Nothings@.
 
 \begin{code}
+#ifdef COMPILING_GHC
 catMaybes :: [Maybe a] -> [a]
 catMaybes []               = []
 catMaybes (Nothing : xs)   = catMaybes xs
 catMaybes (Just x : xs)           = (x : catMaybes xs)
+#endif
 
 allMaybes :: [Maybe a] -> Maybe [a]
 allMaybes [] = Just []
@@ -115,13 +109,6 @@ expectJust err Nothing  = error ("expectJust " ++ err)
 The Maybe monad
 ~~~~~~~~~~~~~~~
 \begin{code}
-#if __HASKELL1__ < 3
-thenMaybe :: Maybe a -> (a -> Maybe b) -> Maybe b
-m `thenMaybe` k = case m of
-                 Nothing -> Nothing
-                 Just a  -> k a
-#endif
-
 seqMaybe :: Maybe a -> Maybe a -> Maybe a
 seqMaybe (Just x) _  = Just x
 seqMaybe Nothing  my = my
@@ -131,12 +118,6 @@ returnMaybe = Just
 
 failMaybe :: Maybe a
 failMaybe = Nothing
-
-mapMaybe :: (a -> Maybe b) -> [a] -> Maybe [b]
-mapMaybe f []    = returnMaybe []
-mapMaybe f (x:xs) = f x                        `thenMaybe` \ x' ->
-                   mapMaybe f xs       `thenMaybe` \ xs' ->
-                   returnMaybe (x':xs')
 \end{code}
 
 Lookup functions
@@ -155,14 +136,11 @@ assocMaybe alist key
     lookup ((tv,ty):rest) = if key == tv then Just ty else lookup rest
 
 #if defined(COMPILING_GHC)
-{-? SPECIALIZE assocMaybe
-       :: [(String,        b)] -> String        -> Maybe b,
-          [(Id,            b)] -> Id            -> Maybe b,
-          [(Class,         b)] -> Class         -> Maybe b,
-          [(Int,           b)] -> Int           -> Maybe b,
-          [(Name,          b)] -> Name          -> Maybe b,
-          [(TyVar,         b)] -> TyVar         -> Maybe b,
-          [(TyVarTemplate, b)] -> TyVarTemplate -> Maybe b
+{-# SPECIALIZE assocMaybe
+       :: [(FAST_STRING,   b)] -> FAST_STRING -> Maybe b
+        , [(Int,           b)] -> Int         -> Maybe b
+        , [(Unique,        b)] -> Unique      -> Maybe b
+        , [(RdrName,       b)] -> RdrName     -> Maybe b
   #-}
 #endif
 \end{code}