summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Maybe.hs
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2014-09-16 19:19:25 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2014-09-16 22:43:17 +0200
commitb47521991a7574f4f3554f7c5444a8c60cfe9efd (patch)
tree55bfb1876f31b841ae9d750aa87489ed6d2dc667 /libraries/base/Data/Maybe.hs
parente7a0f5b66ced8d56d770375e4d35d38c70067559 (diff)
downloadhaskell-b47521991a7574f4f3554f7c5444a8c60cfe9efd.tar.gz
Move `Maybe`-typedef into GHC.Base
This is preparatory work for reintroducing SPECIALISEs that were lost in d94de87252d0fe2ae97341d186b03a2fbe136b04 Differential Revision: https://phabricator.haskell.org/D214
Diffstat (limited to 'libraries/base/Data/Maybe.hs')
-rw-r--r--libraries/base/Data/Maybe.hs46
1 files changed, 0 insertions, 46 deletions
diff --git a/libraries/base/Data/Maybe.hs b/libraries/base/Data/Maybe.hs
index de8eadcd6e..5923ae1061 100644
--- a/libraries/base/Data/Maybe.hs
+++ b/libraries/base/Data/Maybe.hs
@@ -34,52 +34,6 @@ module Data.Maybe
import GHC.Base
-- ---------------------------------------------------------------------------
--- The Maybe type, and instances
-
--- | 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)
-
--- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to
--- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be
--- turned into a monoid simply by adjoining an element @e@ not in @S@
--- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\" Since
--- there is no \"Semigroup\" typeclass providing just 'mappend', we
--- use 'Monoid' instead.
-instance Monoid a => Monoid (Maybe a) where
- mempty = Nothing
- Nothing `mappend` m = m
- m `mappend` Nothing = m
- Just m1 `mappend` Just m2 = Just (m1 `mappend` m2)
-
-instance Functor Maybe where
- fmap _ Nothing = Nothing
- fmap f (Just a) = Just (f a)
-
-instance Applicative Maybe where
- pure = return
- (<*>) = ap
-
-instance Monad Maybe where
- (Just x) >>= k = k x
- Nothing >>= _ = Nothing
-
- (Just _) >> k = k
- Nothing >> _ = Nothing
-
- return = Just
- fail _ = Nothing
-
--- ---------------------------------------------------------------------------
-- Functions over Maybe
-- | The 'maybe' function takes a default value, a function, and a 'Maybe'