1 % ------------------------------------------------------------------------------
2 % $Id: PrelMaybe.lhs,v 1.6 2000/06/30 13:39:36 simonmar Exp $
4 % (c) The University of Glasgow, 1992-2000
7 \section[PrelMaybe]{Module @PrelMaybe@}
12 {-# OPTIONS -fno-implicit-prelude #-}
14 module PrelMaybe where
20 %*********************************************************
22 \subsection{Standard numeric classes}
24 %*********************************************************
27 data Maybe a = Nothing | Just a deriving (Eq, Ord)
29 maybe :: b -> (a -> b) -> Maybe a -> b
31 maybe _ f (Just x) = f x
33 instance Functor Maybe where
34 fmap _ Nothing = Nothing
35 fmap f (Just a) = Just (f a)
37 instance Monad Maybe where
39 Nothing >>= _ = Nothing
42 Nothing >> _ = Nothing
49 %*********************************************************
51 \subsection{Standard numeric classes}
53 %*********************************************************
56 data Either a b = Left a | Right b deriving (Eq, Ord )
58 either :: (a -> c) -> (b -> c) -> Either a b -> c
59 either f _ (Left x) = f x
60 either _ g (Right y) = g y