[project @ 2002-07-04 16:22:02 by simonmar]
[ghc-base.git] / Data / Either.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Data.Either
5 -- Copyright   :  (c) The University of Glasgow 2001
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  experimental
10 -- Portability :  portable
11 --
12 -- The Either type, and associated operations.
13 --
14 -----------------------------------------------------------------------------
15
16 module Data.Either (
17    Either(..),
18    either       -- :: (a -> c) -> (b -> c) -> Either a b -> c
19  ) where
20
21 #ifdef __GLASGOW_HASKELL__
22 import GHC.Base
23 #endif
24
25 {-|
26
27 The 'Either' type represents values with two possibilities: a value of
28 type @'Either' a b@ is either @'Left' a@ or @'Right' b@.
29
30 The 'Either' type is sometimes used to represent a value which is
31 either correct or an error; by convention, the 'Left' constructor is
32 used to hold an error value and the 'Right' constructor is used to
33 hold a correct value (mnemonic: \"right\" also means \"correct\").
34 -}
35 data  Either a b  =  Left a | Right b   deriving (Eq, Ord )
36
37 either                  :: (a -> c) -> (b -> c) -> Either a b -> c
38 either f _ (Left x)     =  f x
39 either _ g (Right y)    =  g y