projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add transitional rules for the alternative layout rule
[ghc-hetmet.git]
/
compiler
/
utils
/
Maybes.lhs
diff --git
a/compiler/utils/Maybes.lhs
b/compiler/utils/Maybes.lhs
index
d4f8346
..
1f443db
100644
(file)
--- a/
compiler/utils/Maybes.lhs
+++ b/
compiler/utils/Maybes.lhs
@@
-10,6
+10,7
@@
module Maybes (
MaybeErr(..), -- Instance of Monad
failME, isSuccess,
MaybeErr(..), -- Instance of Monad
failME, isSuccess,
+ fmapM_maybe,
orElse,
mapCatMaybes,
allMaybes,
orElse,
mapCatMaybes,
allMaybes,
@@
-35,14
+36,9
@@
infixr 4 `orElse`
maybeToBool :: Maybe a -> Bool
maybeToBool Nothing = False
maybeToBool (Just _) = True
maybeToBool :: Maybe a -> Bool
maybeToBool Nothing = False
maybeToBool (Just _) = True
-\end{code}
-
-@catMaybes@ takes a list of @Maybe@s and returns a list of
-the contents of all the @Just@s in it. @allMaybes@ collects
-a list of @Justs@ into a single @Just@, returning @Nothing@ if there
-are any @Nothings@.
-\begin{code}
+-- | Collects a list of @Justs@ into a single @Just@, returning @Nothing@ if
+-- there are any @Nothings@.
allMaybes :: [Maybe a] -> Maybe [a]
allMaybes [] = Just []
allMaybes (Nothing : _) = Nothing
allMaybes :: [Maybe a] -> Maybe [a]
allMaybes [] = Just []
allMaybes (Nothing : _) = Nothing
@@
-50,12
+46,8
@@
allMaybes (Just x : ms) = case allMaybes ms of
Nothing -> Nothing
Just xs -> Just (x:xs)
Nothing -> Nothing
Just xs -> Just (x:xs)
-\end{code}
-
-@firstJust@ takes a list of @Maybes@ and returns the
-first @Just@ if there is one, or @Nothing@ otherwise.
-
-\begin{code}
+-- | Takes a list of @Maybes@ and returns the first @Just@ if there is one, or
+-- @Nothing@ otherwise.
firstJust :: [Maybe a] -> Maybe a
firstJust [] = Nothing
firstJust (Just x : _) = Just x
firstJust :: [Maybe a] -> Maybe a
firstJust [] = Nothing
firstJust (Just x : _) = Just x
@@
-83,6
+75,14
@@
orElse :: Maybe a -> a -> a
Nothing `orElse` y = y
\end{code}
Nothing `orElse` y = y
\end{code}
+\begin{code}
+fmapM_maybe :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
+fmapM_maybe _ Nothing = return Nothing
+fmapM_maybe f (Just x) = do
+ x' <- f x
+ return $ Just x'
+\end{code}
+
%************************************************************************
%* *
\subsection[MaybeT type]{The @MaybeT@ monad transformer}
%************************************************************************
%* *
\subsection[MaybeT type]{The @MaybeT@ monad transformer}