1 % ------------------------------------------------------------------------------
2 % $Id: Maybe.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $
4 % (c) The University of Glasgow, 1992-2000
7 \section[GHC.Maybe]{Module @GHC.Maybe@}
12 {-# OPTIONS -fno-implicit-prelude #-}
14 module GHC.Maybe where
19 %*********************************************************
21 \subsection{Maybe type}
23 %*********************************************************
26 data Maybe a = Nothing | Just a deriving (Eq, Ord)
28 maybe :: b -> (a -> b) -> Maybe a -> b
30 maybe _ f (Just x) = f x
32 instance Functor Maybe where
33 fmap _ Nothing = Nothing
34 fmap f (Just a) = Just (f a)
36 instance Monad Maybe where
38 Nothing >>= _ = Nothing
41 Nothing >> _ = Nothing
48 %*********************************************************
50 \subsection{Either type}
52 %*********************************************************
55 data Either a b = Left a | Right b deriving (Eq, Ord )
57 either :: (a -> c) -> (b -> c) -> Either a b -> c
58 either f _ (Left x) = f x
59 either _ g (Right y) = g y