1 {-# OPTIONS_GHC -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Data.Either
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : portable
12 -- The Either type, and associated operations.
14 -----------------------------------------------------------------------------
18 either -- :: (a -> c) -> (b -> c) -> Either a b -> c
21 #ifdef __GLASGOW_HASKELL__
26 The 'Either' type represents values with two possibilities: a value of
27 type @'Either' a b@ is either @'Left' a@ or @'Right' b@.
29 The 'Either' type is sometimes used to represent a value which is
30 either correct or an error; by convention, the 'Left' constructor is
31 used to hold an error value and the 'Right' constructor is used to
32 hold a correct value (mnemonic: \"right\" also means \"correct\").
34 data Either a b = Left a | Right b deriving (Eq, Ord )
36 -- | Case analysis for the 'Either' type.
37 -- If the value is @'Left' a@, apply the first function to @a@;
38 -- if it is @'Right' b@, apply the second function to @b@.
39 either :: (a -> c) -> (b -> c) -> Either a b -> c
40 either f _ (Left x) = f x
41 either _ g (Right y) = g y
42 #endif /* __GLASGOW_HASKELL__ */