-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
- allMaybes, -- GHCI only
+ allMaybes,
catMaybes,
firstJust,
expectJust,
failMaB,
failMaybe,
seqMaybe,
- mapMaybe, -- GHCI only
returnMaB,
- returnMaybe, -- GHCI only
- thenMaB,
- thenMaybe -- GHCI only
+ returnMaybe,
+ thenMaB
#if ! defined(COMPILING_GHC)
, findJust
CHK_Ubiq() -- debugging consistency check
-#if USE_ATTACK_PRAGMAS
-import Util
-#endif
+import Unique (Unique) -- only for specialising
+
#endif
\end{code}
%************************************************************************
\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
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
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
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}