GHC.Maybe

Safe Haskell None
Language Haskell2010

Description

Maybe type

data Maybe a Source

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 Either type.

Constructors

Nothing
Just a
Instances
Instances details
Monad Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

(>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b Source

(>>) :: Maybe a -> Maybe b -> Maybe b Source

return :: a -> Maybe a Source

Functor Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> Maybe a -> Maybe b Source

(<$) :: a -> Maybe b -> Maybe a Source

MonadFix Maybe

Since: base-2.1

Instance details

Defined in Control.Monad.Fix

Methods

mfix :: (a -> Maybe a) -> Maybe a Source

MonadFail Maybe

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.Fail

Methods

fail :: String -> Maybe a Source

Applicative Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

pure :: a -> Maybe a Source

(<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b Source

liftA2 :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c Source

(*>) :: Maybe a -> Maybe b -> Maybe b Source

(<*) :: Maybe a -> Maybe b -> Maybe a Source

Foldable Maybe

Since: base-2.1

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Maybe m -> m Source

foldMap :: Monoid m => (a -> m) -> Maybe a -> m Source

foldMap' :: Monoid m => (a -> m) -> Maybe a -> m Source

foldr :: (a -> b -> b) -> b -> Maybe a -> b Source

foldr' :: (a -> b -> b) -> b -> Maybe a -> b Source

foldl :: (b -> a -> b) -> b -> Maybe a -> b Source

foldl' :: (b -> a -> b) -> b -> Maybe a -> b Source

foldr1 :: (a -> a -> a) -> Maybe a -> a Source

foldl1 :: (a -> a -> a) -> Maybe a -> a Source

toList :: Maybe a -> [a] Source

null :: Maybe a -> Bool Source

length :: Maybe a -> Int Source

elem :: Eq a => a -> Maybe a -> Bool Source

maximum :: Ord a => Maybe a -> a Source

minimum :: Ord a => Maybe a -> a Source

sum :: Num a => Maybe a -> a Source

product :: Num a => Maybe a -> a Source

Traversable Maybe

Since: base-2.1

Instance details

Defined in Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> Maybe a -> f (Maybe b) Source

sequenceA :: Applicative f => Maybe (f a) -> f (Maybe a) Source

mapM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b) Source

sequence :: Monad m => Maybe (m a) -> m (Maybe a) Source

MonadPlus Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mzero :: Maybe a Source

mplus :: Maybe a -> Maybe a -> Maybe a Source

Alternative Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

empty :: Maybe a Source

(<|>) :: Maybe a -> Maybe a -> Maybe a Source

some :: Maybe a -> Maybe [a] Source

many :: Maybe a -> Maybe [a] Source

MonadZip Maybe

Since: base-4.8.0.0

Instance details

Defined in Control.Monad.Zip

Methods

mzip :: Maybe a -> Maybe b -> Maybe (a, b) Source

mzipWith :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c Source

munzip :: Maybe (a, b) -> (Maybe a, Maybe b) Source

Show1 Maybe

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Maybe a -> ShowS Source

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Maybe a] -> ShowS Source

Read1 Maybe

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Maybe a) Source

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Maybe a] Source

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Maybe a) Source

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Maybe a] Source

Ord1 Maybe

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftCompare :: (a -> b -> Ordering) -> Maybe a -> Maybe b -> Ordering Source

Eq1 Maybe

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftEq :: (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool Source

Eq a => Eq (Maybe a)

Since: base-2.1

Instance details

Defined in GHC.Maybe

Methods

(==) :: Maybe a -> Maybe a -> Bool Source

(/=) :: Maybe a -> Maybe a -> Bool Source

Data a => Data (Maybe a)

Since: base-4.0.0.0

Instance details

Defined in Data.Data

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Maybe a -> c (Maybe a) Source

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Maybe a) Source

toConstr :: Maybe a -> Constr Source

dataTypeOf :: Maybe a -> DataType Source

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Maybe a)) Source

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Maybe a)) Source

gmapT :: (forall b. Data b => b -> b) -> Maybe a -> Maybe a Source

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source

gmapQ :: (forall d. Data d => d -> u) -> Maybe a -> [u] Source

gmapQi :: Int -> (forall d. Data d => d -> u) -> Maybe a -> u Source

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source

Ord a => Ord (Maybe a)

Since: base-2.1

Instance details

Defined in GHC.Maybe

Methods

compare :: Maybe a -> Maybe a -> Ordering Source

(<) :: Maybe a -> Maybe a -> Bool Source

(<=) :: Maybe a -> Maybe a -> Bool Source

(>) :: Maybe a -> Maybe a -> Bool Source

(>=) :: Maybe a -> Maybe a -> Bool Source

max :: Maybe a -> Maybe a -> Maybe a Source

min :: Maybe a -> Maybe a -> Maybe a Source

Read a => Read (Maybe a)

Since: base-2.1

Instance details

Defined in GHC.Read

Show a => Show (Maybe a)

Since: base-2.1

Instance details

Defined in GHC.Show

Methods

showsPrec :: Int -> Maybe a -> ShowS Source

show :: Maybe a -> String Source

showList :: [Maybe a] -> ShowS Source

Generic (Maybe a)

Since: base-4.6.0.0

Instance details

Defined in GHC.Generics

Associated Types

type Rep (Maybe a) :: Type -> Type Source

Methods

from :: Maybe a -> Rep (Maybe a) x Source

to :: Rep (Maybe a) x -> Maybe a Source

Semigroup a => Semigroup (Maybe a)

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

(<>) :: Maybe a -> Maybe a -> Maybe a Source

sconcat :: NonEmpty (Maybe a) -> Maybe a Source

stimes :: Integral b => b -> Maybe a -> Maybe a Source

Semigroup a => Monoid (Maybe a)

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 4.11.0: constraint on inner a value generalised from Monoid to Semigroup.

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mempty :: Maybe a Source

mappend :: Maybe a -> Maybe a -> Maybe a Source

mconcat :: [Maybe a] -> Maybe a Source

Generic1 Maybe

Since: base-4.6.0.0

Instance details

Defined in GHC.Generics

Associated Types

type Rep1 Maybe :: k -> Type Source

Methods

from1 :: forall (a :: k). Maybe a -> Rep1 Maybe a Source

to1 :: forall (a :: k). Rep1 Maybe a -> Maybe a Source

type Rep (Maybe a)
Instance details

Defined in GHC.Generics

type Rep (Maybe a) = D1 ('MetaData "Maybe" "GHC.Maybe" "base" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Rep1 Maybe
Instance details

Defined in GHC.Generics

type Rep1 Maybe = D1 ('MetaData "Maybe" "GHC.Maybe" "base" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.10.2/docs/html/libraries/base-4.14.1.0/GHC-Maybe.html