X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FEither.hs;h=d6261b6f8d0d99f9bd4162df542fae519e61d672;hb=e1a96c7a03ba4c4049195b0d0861136c23d054f5;hp=fa9648c12485bb70b263eb9ed97149d61a6f5547;hpb=746ef6a7fd71bb1e9ebe3cd107c5f9f79f3b7a68;p=ghc-base.git diff --git a/Data/Either.hs b/Data/Either.hs index fa9648c..d6261b6 100644 --- a/Data/Either.hs +++ b/Data/Either.hs @@ -3,7 +3,7 @@ -- | -- Module : Data.Either -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org -- Stability : experimental @@ -20,10 +20,23 @@ module Data.Either ( #ifdef __GLASGOW_HASKELL__ import GHC.Base -#endif +{-| + +The 'Either' type represents values with two possibilities: a value of +type @'Either' a b@ is either @'Left' a@ or @'Right' b@. + +The 'Either' type is sometimes used to represent a value which is +either correct or an error; by convention, the 'Left' constructor is +used to hold an error value and the 'Right' constructor is used to +hold a correct value (mnemonic: \"right\" also means \"correct\"). +-} data Either a b = Left a | Right b deriving (Eq, Ord ) +-- | Case analysis for the 'Either' type. +-- If the value is @'Left' a@, apply the first function to @a@; +-- if it is @'Right' b@, apply the second function to @b@. either :: (a -> c) -> (b -> c) -> Either a b -> c either f _ (Left x) = f x either _ g (Right y) = g y +#endif /* __GLASGOW_HASKELL__ */