Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides linear functions on the standard Maybe
type.
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
Monad Maybe | Since: base-2.1 |
Functor Maybe | Since: base-2.1 |
MonadFail Maybe | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
Applicative Maybe | Since: base-2.1 |
Foldable Maybe | Since: base-2.1 |
Defined in Data.Foldable fold :: Monoid m => Maybe m -> m # foldMap :: Monoid m => (a -> m) -> Maybe a -> m # foldMap' :: Monoid m => (a -> m) -> Maybe a -> m # foldr :: (a -> b -> b) -> b -> Maybe a -> b # foldr' :: (a -> b -> b) -> b -> Maybe a -> b # foldl :: (b -> a -> b) -> b -> Maybe a -> b # foldl' :: (b -> a -> b) -> b -> Maybe a -> b # foldr1 :: (a -> a -> a) -> Maybe a -> a # foldl1 :: (a -> a -> a) -> Maybe a -> a # elem :: Eq a => a -> Maybe a -> Bool # maximum :: Ord a => Maybe a -> a # minimum :: Ord a => Maybe a -> a # | |
Traversable Maybe | Since: base-2.1 |
Show1 Maybe | Since: base-4.9.0.0 |
Read1 Maybe | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Ord1 Maybe | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Eq1 Maybe | Since: base-4.9.0.0 |
MonadPlus Maybe | Since: base-2.1 |
Alternative Maybe | Since: base-2.1 |
Hashable1 Maybe | |
Defined in Data.Hashable.Class | |
Functor Maybe Source # | |
Traversable Maybe Source # | |
Defined in Data.Functor.Linear.Internal.Traversable | |
Generic1 Maybe | |
Lift a => Lift (Maybe a :: Type) | |
Eq a => Eq (Maybe a) | Since: base-2.1 |
Ord a => Ord (Maybe a) | Since: base-2.1 |
Read a => Read (Maybe a) | Since: base-2.1 |
Show a => Show (Maybe a) | Since: base-2.1 |
Generic (Maybe a) | |
Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
SingKind a => SingKind (Maybe a) | Since: base-4.9.0.0 |
Defined in GHC.Generics type DemoteRep (Maybe a) | |
Storable a => Storable (Maybe a) Source # | |
Hashable a => Hashable (Maybe a) | |
Defined in Data.Hashable.Class | |
Consumable a => Consumable (Maybe a) Source # | |
Defined in Data.Unrestricted.Internal.Instances | |
Dupable a => Dupable (Maybe a) Source # | |
Movable a => Movable (Maybe a) Source # | |
(Consumable a, Eq a) => Eq (Maybe a) Source # | |
(Consumable a, Ord a) => Ord (Maybe a) Source # | |
Representable a => Representable (Maybe a) Source # | |
KnownRepresentable a => KnownRepresentable (Maybe a) Source # | |
Defined in Foreign.Marshal.Pure | |
SingI ('Nothing :: Maybe a) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
SingI a2 => SingI ('Just a2 :: Maybe a1) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep1 Maybe | Since: base-4.6.0.0 |
type Rep (Maybe a) | Since: base-4.6.0.0 |
Defined in GHC.Generics | |
data Sing (b :: Maybe a) | |
type DemoteRep (Maybe a) | |
Defined in GHC.Generics | |
type AsKnown (Maybe a) Source # | |
Defined in Foreign.Marshal.Pure |
maybe :: b -> (a %1 -> b) -> Maybe a %1 -> b Source #
maybe b f m
returns (f a)
where a
is in
m
if it exists and b
otherwise
fromMaybe :: a -> Maybe a %1 -> a Source #
fromMaybe default m
is the a
in
m
if it exists and the default
otherwise
maybeToList :: Maybe a %1 -> [a] Source #
maybeToList m
creates a singleton or an empty list
based on the Maybe a
.