[project @ 2001-05-18 09:18:05 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelMaybe.lhs
index 974e5de..42bcd3d 100644 (file)
@@ -1,6 +1,9 @@
+% ------------------------------------------------------------------------------
+% $Id: PrelMaybe.lhs,v 1.6 2000/06/30 13:39:36 simonmar Exp $
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
+% (c) The University of Glasgow, 1992-2000
 %
+
 \section[PrelMaybe]{Module @PrelMaybe@}
 
 The @Maybe@ type.
@@ -11,32 +14,50 @@ The @Maybe@ type.
 module PrelMaybe where
 
 import PrelBase
+\end{code}
+
 
-data  Maybe a  =  Nothing | Just a     deriving (Eq, Ord, Show {- Read -})
+%*********************************************************
+%*                                                     *
+\subsection{Standard numeric classes}
+%*                                                     *
+%*********************************************************
+
+\begin{code}
+data  Maybe a  =  Nothing | Just a     deriving (Eq, Ord)
 
 maybe :: b -> (a -> b) -> Maybe a -> b
-maybe n f Nothing  = n
-maybe n f (Just x) = f x
+maybe n _ Nothing  = n
+maybe _ f (Just x) = f x
 
 instance  Functor Maybe  where
-    map f Nothing       = Nothing
-    map f (Just a)      = Just (f a)
+    fmap _ Nothing       = Nothing
+    fmap f (Just a)      = Just (f a)
 
 instance  Monad Maybe  where
     (Just x) >>= k      = k x
-    Nothing  >>= k      = Nothing
+    Nothing  >>= _      = Nothing
 
-    (Just x) >>  k      = k
-    Nothing  >>  k      = Nothing
+    (Just _) >>  k      = k
+    Nothing  >>  _      = Nothing
 
     return              = Just
+    fail _             = Nothing
+\end{code}
+
 
-instance  MonadZero Maybe  where
-    zero                = Nothing
+%*********************************************************
+%*                                                     *
+\subsection{Standard numeric classes}
+%*                                                     *
+%*********************************************************
+
+\begin{code}
+data  Either a b  =  Left a | Right b  deriving (Eq, Ord )
 
-instance  MonadPlus Maybe  where
-    Nothing ++ ys       = ys
-    xs      ++ ys       = xs
+either                  :: (a -> c) -> (b -> c) -> Either a b -> c
+either f _ (Left x)     =  f x
+either _ g (Right y)    =  g y
 \end{code}