Agda-2.6.0.1: A dependently typed functional programming language and proof assistant

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.Maybe.Strict

Contents

- Orphan instances

Description

A strict version of the `Maybe` type.

Import qualified, as in `import qualified Agda.Utils.Maybe.Strict as Strict`

Copyright : (c) 2006-2007 Roman Leshchinskiy (c) 2013 Simon Meier License : BSD-style (see the file LICENSE)

Copyright : (c) 2014 Andreas Abel

Synopsis

- maybe :: b -> (a -> b) -> Maybe a -> b
- fromMaybe :: a -> Maybe a -> a
- fromJust :: Maybe a -> a
- isNothing :: Maybe a -> Bool
- isJust :: Maybe a -> Bool
- data Maybe a
  - = Nothing
  - | Just !a
- toStrict :: Maybe a -> Maybe a
- toLazy :: Maybe a -> Maybe a
- listToMaybe :: [a] -> Maybe a
- maybeToList :: Maybe a -> [a]
- catMaybes :: [Maybe a] -> [a]
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- unionMaybeWith :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
- unzipMaybe :: Maybe (a, b) -> (Maybe a, Maybe b)
- filterMaybe :: (a -> Bool) -> a -> Maybe a
- forMaybe :: [a] -> (a -> Maybe b) -> [b]
- caseMaybe :: Maybe a -> b -> (a -> b) -> b
- maybeM :: Monad m => m b -> (a -> m b) -> m (Maybe a) -> m b
- fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a
- caseMaybeM :: Monad m => m (Maybe a) -> m b -> (a -> m b) -> m b
- ifJustM :: Monad m => m (Maybe a) -> (a -> m b) -> m b -> m b
- whenJust :: Monad m => Maybe a -> (a -> m ()) -> m ()
- whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()

# Documentation

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.

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.

fromJust :: Maybe a -> a Source #

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

isNothing :: Maybe a -> Bool Source #

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

isJust :: Maybe a -> Bool Source #

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

data Maybe a Source #

The type of strict optional values.

Constructors

Nothing |
Just !a |

Instances

Functor Maybe |
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 Agda.Utils.Maybe.Strict

Methods

fold :: Monoid m => Maybe m -> 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 Agda.Utils.Maybe.Strict 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 #
KillRange Range Source # |
Instance details Defined in Agda.Syntax.Position Methods killRange :: KillRangeT Range Source #
SetRange Range Source # |
Instance details Defined in Agda.Syntax.Position Methods setRange :: Range -> Range -> Range Source #
HasRange Range Source # |
Instance details Defined in Agda.Syntax.Position Methods getRange :: Range -> Range Source #
HasRange Interval Source # |
Instance details Defined in Agda.Syntax.Position Methods getRange :: Interval -> Range Source #
FreshName Range Source # |
Instance details Defined in Agda.TypeChecking.Monad.Base Methods freshName_ :: MonadTCState m => Range -> m Name Source #
EmbPrj Range Source # | Ranges are always deserialised as `noRange`.
Instance details Defined in Agda.TypeChecking.Serialise.Instances.Common Methods icode :: Range -> S Int32 Source # icod_ :: Range -> S Int32 Source # value :: Int32 -> R Range Source #
PrettyTCM Range Source # |
Instance details Defined in Agda.TypeChecking.Pretty Methods prettyTCM :: Range -> TCM Doc Source #
Subst Term Range Source # |
Instance details Defined in Agda.TypeChecking.Substitute Methods applySubst :: Substitution' Term -> Range -> Range Source #
Eq a => Eq (Maybe a) |
Instance details Defined in Data.Strict.Maybe Methods (==) :: Maybe a -> Maybe a -> Bool Source # (/=) :: Maybe a -> Maybe a -> Bool Source #
Data a => Data (Maybe a) Source # |

Instance details

Defined in Agda.Utils.Maybe.Strict

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)) -> Maybe0 (c (Maybe a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe0 (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 :: (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) |
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 #
Read a => Read (Maybe a) |
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) |
Instance details Defined in Data.Strict.Maybe Methods showsPrec :: Int -> Maybe a -> ShowS Source # show :: Maybe a -> String Source # showList :: [Maybe a] -> ShowS Source #
Show a => Show (Range' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods showsPrec :: Int -> Range' (Maybe a) -> ShowS Source # show :: Range' (Maybe a) -> String Source # showList :: [Range' (Maybe a)] -> ShowS Source #
Show a => Show (Interval' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods showsPrec :: Int -> Interval' (Maybe a) -> ShowS Source # show :: Interval' (Maybe a) -> String Source # showList :: [Interval' (Maybe a)] -> ShowS Source #
Show a => Show (Position' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods showsPrec :: Int -> Position' (Maybe a) -> ShowS Source # show :: Position' (Maybe a) -> String Source # showList :: [Position' (Maybe a)] -> ShowS Source #
Generic (Maybe a) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict 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) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict 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) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict Methods mempty :: Maybe a Source # mappend :: Maybe a -> Maybe a -> Maybe a Source # mconcat :: [Maybe a] -> Maybe a Source #
Binary a => Binary (Maybe a) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict 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 Agda.Utils.Maybe.Strict Methods rnf :: Maybe a -> () Source #
Null (Maybe a) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict Methods empty :: Maybe a Source # null :: Maybe a -> Bool Source #
Pretty a => Pretty (Range' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods pretty :: Range' (Maybe a) -> Doc Source # prettyPrec :: Int -> Range' (Maybe a) -> Doc Source # prettyList :: [Range' (Maybe a)] -> Doc Source #
Pretty a => Pretty (Interval' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods pretty :: Interval' (Maybe a) -> Doc Source # prettyPrec :: Int -> Interval' (Maybe a) -> Doc Source # prettyList :: [Interval' (Maybe a)] -> Doc Source #
Pretty a => Pretty (Position' (Maybe a)) Source # |
Instance details Defined in Agda.Syntax.Position Methods pretty :: Position' (Maybe a) -> Doc Source # prettyPrec :: Int -> Position' (Maybe a) -> Doc Source # prettyList :: [Position' (Maybe a)] -> Doc Source #
EmbPrj a => EmbPrj (Maybe a) Source # |
Instance details Defined in Agda.TypeChecking.Serialise.Instances.Common Methods icode :: Maybe a -> S Int32 Source # icod_ :: Maybe a -> S Int32 Source # value :: Int32 -> R (Maybe a) Source #
FreshName (Range, String) Source # |
Instance details Defined in Agda.TypeChecking.Monad.Base Methods freshName_ :: MonadTCState m => (Range, String) -> m Name Source #
type Rep (Maybe a) Source # |
Instance details Defined in Agda.Utils.Maybe.Strict type Rep (Maybe a) = D1 (MetaData "Maybe" "Data.Strict.Maybe" "strict-0.3.2-5w6PBW5d25zBwMiv48Xbom" False) (C1 (MetaCons "Nothing" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Just" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)))

toStrict :: Maybe a -> Maybe a Source #

toLazy :: Maybe a -> Maybe a Source #

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.

unionMaybeWith :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a Source #

`unionWith` for collections of size <= 1.

unzipMaybe :: Maybe (a, b) -> (Maybe a, Maybe b) Source #

Unzipping a list of length <= 1.

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

Filtering a singleton list.

    filterMaybe p a = listToMaybe (filter p [a])

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

Version of `mapMaybe` with different argument ordering.

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

Version of `maybe` with different argument ordering. Often, we want to case on a `Maybe`, do something interesting in the `Just` case, but only a default action in the `Nothing` case. Then, the argument ordering of `caseMaybe` is preferable.

    caseMaybe m err f = flip (maybe err) m f

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

Monadic version of `maybe`.

fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a Source #

Monadic version of `fromMaybe`.

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

Monadic version of `caseMaybe`. That is, `maybeM` with a different argument ordering.

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

`caseMaybeM` with flipped branches.

whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () Source #

A more telling name for `forM` for the `Maybe` collection type. Or: `caseMaybe` without the `Nothing` case.

whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m () Source #

`caseMaybeM` without the `Nothing` case.

# Orphan instances

Foldable Maybe Source # |

Instance details

Methods

fold :: Monoid m => Maybe m -> 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 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 #
Data a => Data (Maybe a) Source # |

Instance details

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)) -> Maybe0 (c (Maybe a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe0 (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 :: (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 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) Source # |
Instance details 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) Source # |
Instance details Methods mempty :: Maybe a Source # mappend :: Maybe a -> Maybe a -> Maybe a Source # mconcat :: [Maybe a] -> Maybe a Source #
Binary a => Binary (Maybe a) Source # |
Instance details Methods put :: Maybe a -> Put Source # get :: Get (Maybe a) Source # putList :: [Maybe a] -> Put Source #
NFData a => NFData (Maybe a) Source # |
Instance details Methods rnf :: Maybe a -> () Source #
Null (Maybe a) Source # |
Instance details Methods empty :: Maybe a Source # null :: Maybe a -> Bool Source #