+% ------------------------------------------------------------------------------
+% $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.
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}