strict-0.5.1: Strict data types and String IO.

Safe Haskell | Safe
Language | Haskell2010

Data.Strict.Maybe

Description

The strict variant of the standard Haskell `Maybe` type and the corresponding variants of the functions from Data.Maybe.

Note that in contrast to the standard lazy `Maybe` type, the strict `Maybe` type is not an applicative functor, and therefore also not a monad. The problem is the homomorphism law, which states that

    pure f <*> pure x = pure (f x)  -- must hold for all f

This law does not hold for the expected applicative functor instance of `Maybe`, as this instance does not satisfy `pure f <*> pure _|_ = pure (f _|_)` for `f = const`.

Synopsis

- data Maybe a
  - = Nothing
  - | Just !a
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- fromJust :: Maybe a -> a
- fromMaybe :: a -> Maybe a -> a
- maybe :: b -> (a -> b) -> Maybe a -> b
- listToMaybe :: [a] -> Maybe a
- maybeToList :: Maybe a -> [a]
- catMaybes :: [Maybe a] -> [a]
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]

# Documentation

data Maybe a Source #

The type of strict optional values.

Constructors

Nothing |
Just !a |

#### Instances

Instances details

Eq1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods liftEq :: (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool Source #
Ord1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods liftCompare :: (a -> b -> Ordering) -> Maybe a -> Maybe b -> Ordering Source #
Read1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe 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 #
Show1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Maybe a -> ShowS Source # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Maybe a] -> ShowS Source #
NFData1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods liftRnf :: (a -> ()) -> Maybe a -> () Source #
Functor Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods fmap :: (a -> b) -> Maybe a -> Maybe b Source # (<$) :: a -> Maybe b -> Maybe a Source #
Foldable Maybe Source # |

Instance details

Defined in Data.Strict.Maybe

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 Source # |
Instance details Defined in Data.Strict.Maybe 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 #
Hashable1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe Methods liftHashWithSalt :: (Int -> a -> Int) -> Int -> Maybe a -> Int Source #
Generic1 Maybe Source # |

Instance details

Defined in Data.Strict.Maybe

Associated Types

type Rep1 Maybe |
Instance details Defined in Data.Strict.Maybe type Rep1 Maybe = D1 ('MetaData "Maybe" "Data.Strict.Maybe" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))

Methods

from1 :: Maybe a -> Rep1 Maybe a Source #

to1 :: Rep1 Maybe a -> Maybe a Source #

Binary a => Binary (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods put :: Maybe a -> Put Source # get :: Get (Maybe a) Source # putList :: [Maybe a] -> Put Source #
NFData a => NFData (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods rnf :: Maybe a -> () Source #
Semigroup a => Monoid (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods mempty :: Maybe a Source # mappend :: Maybe a -> Maybe a -> Maybe a Source # mconcat :: [Maybe a] -> Maybe a Source #
Semigroup a => Semigroup (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods (<>) :: Maybe a -> Maybe a -> Maybe a Source # sconcat :: NonEmpty (Maybe a) -> Maybe a Source # stimes :: Integral b => b -> Maybe a -> Maybe a Source #
Data a => Data (Maybe a) Source # |

Instance details

Defined in Data.Strict.Maybe

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 #

Generic (Maybe a) Source # |

Instance details

Defined in Data.Strict.Maybe

Associated Types

type Rep (Maybe a) |
Instance details Defined in Data.Strict.Maybe type Rep (Maybe a) = D1 ('MetaData "Maybe" "Data.Strict.Maybe" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

Methods

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

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

Read a => Read (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods readsPrec :: Int -> ReadS (Maybe a) Source # readList :: ReadS [Maybe a] Source # readPrec :: ReadPrec (Maybe a) Source # readListPrec :: ReadPrec [Maybe a] Source #
Show a => Show (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods showsPrec :: Int -> Maybe a -> ShowS Source # show :: Maybe a -> String Source # showList :: [Maybe a] -> ShowS Source #
Eq a => Eq (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods (==) :: Maybe a -> Maybe a -> Bool Source # (/=) :: Maybe a -> Maybe a -> Bool Source #
Ord a => Ord (Maybe a) Source # |
Instance details Defined in Data.Strict.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 #
Hashable a => Hashable (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe Methods hashWithSalt :: Int -> Maybe a -> Int Source # hash :: Maybe a -> Int Source #
Strict (Maybe a) (Maybe a) Source # |
Instance details Defined in Data.Strict.Classes Methods toStrict :: Maybe a -> Maybe a Source # toLazy :: Maybe a -> Maybe a Source #
type Rep1 Maybe Source # |
Instance details Defined in Data.Strict.Maybe type Rep1 Maybe = D1 ('MetaData "Maybe" "Data.Strict.Maybe" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))
type Rep (Maybe a) Source # |
Instance details Defined in Data.Strict.Maybe type Rep (Maybe a) = D1 ('MetaData "Maybe" "Data.Strict.Maybe" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "Nothing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Just" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

isJust :: Maybe a -> Bool Source #

Yields `True` iff the argument is of the form `Just _`.

isNothing :: Maybe a -> Bool Source #

Yields `True` iff the argument is `Nothing`.

fromJust :: Maybe a -> a Source #

Extracts the element out of a `Just` and throws an error if the argument is `Nothing`.

fromMaybe :: a -> Maybe a -> a Source #

Given a default value and a `Maybe`, yield the default value if the `Maybe` argument is `Nothing` and extract the value out of the `Just` otherwise.

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

Given a default value, a function and a `Maybe` value, yields the default value if the `Maybe` value is `Nothing` and applies the function to the value stored in the `Just` otherwise.

listToMaybe :: [a] -> Maybe a Source #

Analogous to `listToMaybe` in Data.Maybe.

maybeToList :: Maybe a -> [a] Source #

Analogous to `maybeToList` in Data.Maybe.

catMaybes :: [Maybe a] -> [a] Source #

Analogous to `catMaybes` in Data.Maybe.

mapMaybe :: (a -> Maybe b) -> [a] -> [b] Source #

Analogous to `mapMaybe` in Data.Maybe.