X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FMaybe.hs;h=195daab859660e79ff4ab468b08d4a91235f87a2;hb=fd0f2fbadf218f080a60c392221820a9f07933df;hp=d0b5c18a96a154d39bb7d28bcc304c4458e644d1;hpb=746ef6a7fd71bb1e9ebe3cd107c5f9f79f3b7a68;p=ghc-base.git diff --git a/Data/Maybe.hs b/Data/Maybe.hs index d0b5c18..195daab 100644 --- a/Data/Maybe.hs +++ b/Data/Maybe.hs @@ -3,7 +3,7 @@ -- | -- 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 @@ -35,10 +35,37 @@ import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base #endif +#ifdef __NHC__ +import Prelude +import Prelude (Maybe(..), maybe) +import Maybe + ( isJust + , isNothing + , fromJust + , fromMaybe + , listToMaybe + , maybeToList + , catMaybes + , mapMaybe + ) +#else + +#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 @@ -60,6 +87,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 @@ -95,3 +123,4 @@ mapMaybe f (x:xs) = Nothing -> rs Just r -> r:rs +#endif /* else not __NHC__ */