X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FMaybe.hs;h=32101b7eaf059320ead2ab76b10e7a80a1938e45;hb=ac29f3c340fca6b7362e089fd439cb0cf5e092f8;hp=3f1ffad76562cb7ab74e796fff2fc264e8539f43;hpb=d9e5fa673b75cdffbcd0e85cdcc98d706acbb29a;p=haskell-directory.git diff --git a/Data/Maybe.hs b/Data/Maybe.hs index 3f1ffad..32101b7 100644 --- a/Data/Maybe.hs +++ b/Data/Maybe.hs @@ -1,16 +1,14 @@ {-# OPTIONS -fno-implicit-prelude #-} ----------------------------------------------------------------------------- --- +-- | -- Module : Data.Maybe -- 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 -- Portability : portable -- --- $Id: Maybe.hs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ --- -- The Maybe type, and associated operations. -- ----------------------------------------------------------------------------- @@ -40,7 +38,18 @@ import GHC.Base -- --------------------------------------------------------------------------- -- The Maybe type, and instances -data Maybe a = Nothing | Just a deriving (Eq, Ord) +-- | The 'Maybe' type encapsulates an optional value. A value of type +-- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@), +-- or it is empty (represented as 'Nothing'). Using 'Maybe' is a good way to +-- deal with errors or exceptional cases without resorting to drastic +-- measures such as 'error'. +-- +-- The 'Maybe' type is also a monad. It is a simple kind of error +-- monad, where all errors are represented by 'Nothing'. A richer +-- error monad can be built using the 'Data.Either.Either' type. + +data Maybe a = Nothing | Just a + deriving (Eq, Ord) instance Functor Maybe where fmap _ Nothing = Nothing