X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FMaybe.hs;h=1a1467f7f3ad43eee102589b2c19583d17203584;hb=6bbd4780e49f69a08ae373b5a07bd15b037013f7;hp=36e684e1ea62cfd6de0714a4b9294f7d85f68832;hpb=9fa9bc17072a58c0bae2cce4764d38677e96ac29;p=ghc-base.git diff --git a/Data/Maybe.hs b/Data/Maybe.hs index 36e684e..1a1467f 100644 --- a/Data/Maybe.hs +++ b/Data/Maybe.hs @@ -3,14 +3,12 @@ -- | -- 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.4 2002/04/24 16:31:39 simonmar Exp $ --- -- The Maybe type, and associated operations. -- ----------------------------------------------------------------------------- @@ -37,10 +35,22 @@ import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base #endif +#ifndef __HUGS__ -- --------------------------------------------------------------------------- -- 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 @@ -62,6 +72,7 @@ instance Monad Maybe where maybe :: b -> (a -> b) -> Maybe a -> b maybe n _ Nothing = n maybe _ f (Just x) = f x +#endif /* __HUGS__ */ isJust :: Maybe a -> Bool isJust Nothing = False