projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[project @ 1997-05-19 00:12:10 by sof]
[ghc-hetmet.git]
/
ghc
/
compiler
/
utils
/
Maybes.lhs
diff --git
a/ghc/compiler/utils/Maybes.lhs
b/ghc/compiler/utils/Maybes.lhs
index
5ed4ac3
..
2542141
100644
(file)
--- a/
ghc/compiler/utils/Maybes.lhs
+++ b/
ghc/compiler/utils/Maybes.lhs
@@
-12,8
+12,8
@@
module Maybes (
-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
+ mapMaybe,
allMaybes,
allMaybes,
- catMaybes,
firstJust,
expectJust,
maybeToBool,
firstJust,
expectJust,
maybeToBool,
@@
-28,7
+28,9
@@
module Maybes (
returnMaybe,
thenMaB
returnMaybe,
thenMaB
-#if ! defined(COMPILING_GHC)
+#if defined(COMPILING_GHC)
+ , catMaybes
+#else
, findJust
, foldlMaybeErrs
, listMaybeErrs
, findJust
, foldlMaybeErrs
, listMaybeErrs
@@
-37,10
+39,13
@@
module Maybes (
#if defined(COMPILING_GHC)
#if defined(COMPILING_GHC)
-CHK_Ubiq() -- debugging consistency check
+CHK_Ubiq() -- debugging consistency check
-import Unique (Unique) -- only for specialising
+IMPORT_DELOOPER( SpecLoop ) -- Specialisation
+import Unique (Unique) -- only for specialising
+#else
+import Maybe -- renamer will tell us if there are any conflicts
#endif
\end{code}
#endif
\end{code}
@@
-63,10
+68,12
@@
a list of @Justs@ into a single @Just@, returning @Nothing@ if there
are any @Nothings@.
\begin{code}
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)
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 []
allMaybes :: [Maybe a] -> Maybe [a]
allMaybes [] = Just []
@@
-74,6
+81,12
@@
allMaybes (Nothing : ms) = Nothing
allMaybes (Just x : ms) = case (allMaybes ms) of
Nothing -> Nothing
Just xs -> Just (x:xs)
allMaybes (Just x : ms) = case (allMaybes ms) of
Nothing -> Nothing
Just xs -> Just (x:xs)
+
+mapMaybe :: (a -> Maybe b) -> [a] -> [b]
+mapMaybe f [] = []
+mapMaybe f (x:xs) = case f x of
+ Just y -> y : mapMaybe f xs
+ Nothing -> mapMaybe f xs
\end{code}
@firstJust@ takes a list of @Maybes@ and returns the
\end{code}
@firstJust@ takes a list of @Maybes@ and returns the
@@
-135,7
+148,6
@@
assocMaybe alist key
:: [(FAST_STRING, b)] -> FAST_STRING -> Maybe b
, [(Int, b)] -> Int -> Maybe b
, [(Unique, b)] -> Unique -> Maybe b
:: [(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}
#-}
#endif
\end{code}