X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Fcompiler%2Futils%2FMaybes.lhs;h=2542141dfae0f40ffb9a283cd9ee8a8884996b76;hb=dcef38bab91d45b56f7cf3ceeec96303d93728bb;hp=5ed4ac316f492165b8993789408350ad3b5df691;hpb=26741ec416bae2c502ef00a2ba0e79050a32cb67;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/Maybes.lhs b/ghc/compiler/utils/Maybes.lhs index 5ed4ac3..2542141 100644 --- 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(..), + mapMaybe, allMaybes, - catMaybes, firstJust, expectJust, maybeToBool, @@ -28,7 +28,9 @@ module Maybes ( returnMaybe, thenMaB -#if ! defined(COMPILING_GHC) +#if defined(COMPILING_GHC) + , catMaybes +#else , findJust , foldlMaybeErrs , listMaybeErrs @@ -37,10 +39,13 @@ module Maybes ( #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} @@ -63,10 +68,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 [] @@ -74,6 +81,12 @@ allMaybes (Nothing : ms) = Nothing 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 @@ -135,7 +148,6 @@ assocMaybe alist key :: [(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}