| Portability | portable |
|---|---|
| Stability | stable |
| Maintainer | libraries@haskell.org |
| Safe Haskell | Trustworthy |
Data.Maybe
Description
The Maybe type, and associated operations.
Synopsis
Documentation
The Maybe type encapsulates an optional value. A value of type
either contains a value of type Maybe aa (represented as ),
or it is empty (represented as Just aNothing ). 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 Either type.
Instances
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.
listToMaybe :: [a] -> Maybe aSource
The listToMaybe function returns Nothing on an empty list
or where Just aa is the first element of the list.
maybeToList :: Maybe a -> [a]Source
The maybeToList function returns an empty list when given
Nothing or a singleton list when not given Nothing .