2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrelMaybe]{Module @PrelMaybe@}
9 {-# OPTIONS -fno-implicit-prelude #-}
11 module PrelMaybe where
17 %*********************************************************
19 \subsection{Standard numeric classes}
21 %*********************************************************
24 data Maybe a = Nothing | Just a deriving (Eq, Ord)
26 maybe :: b -> (a -> b) -> Maybe a -> b
28 maybe _ f (Just x) = f x
30 instance Functor Maybe where
31 fmap _ Nothing = Nothing
32 fmap f (Just a) = Just (f a)
34 instance Monad Maybe where
36 Nothing >>= _ = Nothing
39 Nothing >> _ = Nothing
46 %*********************************************************
48 \subsection{Standard numeric classes}
50 %*********************************************************
53 data Either a b = Left a | Right b deriving (Eq, Ord )
55 either :: (a -> c) -> (b -> c) -> Either a b -> c
56 either f _ (Left x) = f x
57 either _ g (Right y) = g y