ghc-lib-parser-9.10.1.20250103: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Data.Maybe

Contents

- MaybeT

Synopsis

- module Data.Maybe
- data MaybeErr err val
  - = Succeeded val
  - | Failed err
- failME :: err -> MaybeErr err val
- isSuccess :: MaybeErr err val -> Bool
- orElse :: Maybe a -> a -> a
- firstJust :: Maybe a -> Maybe a -> Maybe a
- firstJusts :: Foldable f => f (Maybe a) -> Maybe a
- firstJustsM :: (Monad m, Foldable f) => f (m (Maybe a)) -> m (Maybe a)
- whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m ()
- expectJust :: HasCallStack => String -> Maybe a -> a
- rightToMaybe :: Either a b -> Maybe b
- newtype MaybeT (m :: Type -> Type) a = MaybeT {
  - runMaybeT :: m (Maybe a)
  }
- liftMaybeT :: Monad m => m a -> MaybeT m a
- tryMaybeT :: IO a -> MaybeT IO a

# Documentation

module Data.Maybe

data MaybeErr err val #

Constructors

Succeeded val |
Failed err |

#### Instances

Instances details

Applicative (MaybeErr err) # |
Instance details Defined in GHC.Data.Maybe Methods pure :: a -> MaybeErr err a # (<*>) :: MaybeErr err (a -> b) -> MaybeErr err a -> MaybeErr err b # liftA2 :: (a -> b -> c) -> MaybeErr err a -> MaybeErr err b -> MaybeErr err c # (*>) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err b # (<*) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err a #
Functor (MaybeErr err) # |
Instance details Defined in GHC.Data.Maybe Methods fmap :: (a -> b) -> MaybeErr err a -> MaybeErr err b # (<$) :: a -> MaybeErr err b -> MaybeErr err a #
Monad (MaybeErr err) # |
Instance details Defined in GHC.Data.Maybe Methods (>>=) :: MaybeErr err a -> (a -> MaybeErr err b) -> MaybeErr err b # (>>) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err b # return :: a -> MaybeErr err a #

failME :: err -> MaybeErr err val #

isSuccess :: MaybeErr err val -> Bool #

orElse :: Maybe a -> a -> a infixr 4 #

Flipped version of `fromMaybe`, useful for chaining.

firstJust :: Maybe a -> Maybe a -> Maybe a #

firstJusts :: Foldable f => f (Maybe a) -> Maybe a #

Takes a list of `Maybes` and returns the first `Just` if there is one, or `Nothing` otherwise.

firstJustsM :: (Monad m, Foldable f) => f (m (Maybe a)) -> m (Maybe a) #

Takes computations returnings `Maybes`; tries each one in order. The first one to return a `Just` wins. Returns `Nothing` if all computations return `Nothing`.

whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m () #

expectJust :: HasCallStack => String -> Maybe a -> a #

rightToMaybe :: Either a b -> Maybe b #

# MaybeT

newtype MaybeT (m :: Type -> Type) a #

The parameterizable maybe monad, obtained by composing an arbitrary monad with the `Maybe` monad.

Computations are actions that may produce a value or exit.

The `return` function yields a computation that produces that value, while `>>=` sequences two subcomputations, exiting if either computation does.

Constructors

MaybeT |

Fields

- runMaybeT :: m (Maybe a)

#### Instances

Instances details

MonadTrans MaybeT |
Instance details Defined in Control.Monad.Trans.Maybe Methods lift :: Monad m => m a -> MaybeT m a #
Functor m => Generic1 (MaybeT m :: Type -> Type) |

Instance details

Defined in Control.Monad.Trans.Maybe

Associated Types

type Rep1 (MaybeT m :: Type -> Type) |
Instance details Defined in Control.Monad.Trans.Maybe type Rep1 (MaybeT m :: Type -> Type) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.1-inplace" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 Maybe)))

Methods

from1 :: MaybeT m a -> Rep1 (MaybeT m) a #

to1 :: Rep1 (MaybeT m) a -> MaybeT m a #

MonadIO m => MonadIO (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftIO :: IO a -> MaybeT m a #
MonadZip m => MonadZip (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mzip :: MaybeT m a -> MaybeT m b -> MaybeT m (a, b) # mzipWith :: (a -> b -> c) -> MaybeT m a -> MaybeT m b -> MaybeT m c # munzip :: MaybeT m (a, b) -> (MaybeT m a, MaybeT m b) #
Eq1 m => Eq1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftEq :: (a -> b -> Bool) -> MaybeT m a -> MaybeT m b -> Bool #
Ord1 m => Ord1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftCompare :: (a -> b -> Ordering) -> MaybeT m a -> MaybeT m b -> Ordering #
Read1 m => Read1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (MaybeT m a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [MaybeT m a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (MaybeT m a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [MaybeT m a] #
Show1 m => Show1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> MaybeT m a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [MaybeT m a] -> ShowS #
Contravariant m => Contravariant (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods contramap :: (a' -> a) -> MaybeT m a -> MaybeT m a' # (>$) :: b -> MaybeT m b -> MaybeT m a #
MonadCatch m => MonadCatch (MaybeT m) | Catches exceptions from the base monad.
Instance details Defined in Control.Monad.Catch Methods catch :: (HasCallStack, Exception e) => MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a #
MonadMask m => MonadMask (MaybeT m) | Since: exceptions-0.10.0
Instance details Defined in Control.Monad.Catch Methods mask :: HasCallStack => ((forall a. MaybeT m a -> MaybeT m a) -> MaybeT m b) -> MaybeT m b # uninterruptibleMask :: HasCallStack => ((forall a. MaybeT m a -> MaybeT m a) -> MaybeT m b) -> MaybeT m b # generalBracket :: HasCallStack => MaybeT m a -> (a -> ExitCase b -> MaybeT m c) -> (a -> MaybeT m b) -> MaybeT m (b, c) #
MonadThrow m => MonadThrow (MaybeT m) | Throws exceptions into the base monad.
Instance details Defined in Control.Monad.Catch Methods throwM :: (HasCallStack, Exception e) => e -> MaybeT m a #
(Functor m, Monad m) => Alternative (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods empty :: MaybeT m a # (<|>) :: MaybeT m a -> MaybeT m a -> MaybeT m a # some :: MaybeT m a -> MaybeT m [a] # many :: MaybeT m a -> MaybeT m [a] #
(Functor m, Monad m) => Applicative (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods pure :: a -> MaybeT m a # (<*>) :: MaybeT m (a -> b) -> MaybeT m a -> MaybeT m b # liftA2 :: (a -> b -> c) -> MaybeT m a -> MaybeT m b -> MaybeT m c # (*>) :: MaybeT m a -> MaybeT m b -> MaybeT m b # (<*) :: MaybeT m a -> MaybeT m b -> MaybeT m a #
Functor m => Functor (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods fmap :: (a -> b) -> MaybeT m a -> MaybeT m b # (<$) :: a -> MaybeT m b -> MaybeT m a #
Monad m => Monad (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods (>>=) :: MaybeT m a -> (a -> MaybeT m b) -> MaybeT m b # (>>) :: MaybeT m a -> MaybeT m b -> MaybeT m b # return :: a -> MaybeT m a #
Monad m => MonadPlus (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mzero :: MaybeT m a # mplus :: MaybeT m a -> MaybeT m a -> MaybeT m a #
Monad m => MonadFail (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods fail :: String -> MaybeT m a #
MonadFix m => MonadFix (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mfix :: (a -> MaybeT m a) -> MaybeT m a #
Foldable f => Foldable (MaybeT f) |

Instance details

Defined in Control.Monad.Trans.Maybe

Methods

fold :: Monoid m => MaybeT f m -> m #

foldMap :: Monoid m => (a -> m) -> MaybeT f a -> m #

foldMap' :: Monoid m => (a -> m) -> MaybeT f a -> m #

foldr :: (a -> b -> b) -> b -> MaybeT f a -> b #

foldr' :: (a -> b -> b) -> b -> MaybeT f a -> b #

foldl :: (b -> a -> b) -> b -> MaybeT f a -> b #

foldl' :: (b -> a -> b) -> b -> MaybeT f a -> b #

foldr1 :: (a -> a -> a) -> MaybeT f a -> a #

foldl1 :: (a -> a -> a) -> MaybeT f a -> a #

toList :: MaybeT f a -> [a] #

null :: MaybeT f a -> Bool #

length :: MaybeT f a -> Int #

elem :: Eq a => a -> MaybeT f a -> Bool #

maximum :: Ord a => MaybeT f a -> a #

minimum :: Ord a => MaybeT f a -> a #

sum :: Num a => MaybeT f a -> a #

product :: Num a => MaybeT f a -> a #

Traversable f => Traversable (MaybeT f) |
Instance details Defined in Control.Monad.Trans.Maybe Methods traverse :: Applicative f0 => (a -> f0 b) -> MaybeT f a -> f0 (MaybeT f b) # sequenceA :: Applicative f0 => MaybeT f (f0 a) -> f0 (MaybeT f a) # mapM :: Monad m => (a -> m b) -> MaybeT f a -> m (MaybeT f b) # sequence :: Monad m => MaybeT f (m a) -> m (MaybeT f a) #
(Monad m, HasDynFlags m) => HasDynFlags (MaybeT m) # |
Instance details Defined in GHC.Driver.DynFlags Methods getDynFlags :: MaybeT m DynFlags #
Generic (MaybeT m a) |

Instance details

Defined in Control.Monad.Trans.Maybe

Associated Types

type Rep (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe type Rep (MaybeT m a) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.1-inplace" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Maybe a)))))

Methods

from :: MaybeT m a -> Rep (MaybeT m a) x #

to :: Rep (MaybeT m a) x -> MaybeT m a #

(Read1 m, Read a) => Read (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods readsPrec :: Int -> ReadS (MaybeT m a) # readList :: ReadS [MaybeT m a] # readPrec :: ReadPrec (MaybeT m a) # readListPrec :: ReadPrec [MaybeT m a] #
(Show1 m, Show a) => Show (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods showsPrec :: Int -> MaybeT m a -> ShowS # show :: MaybeT m a -> String # showList :: [MaybeT m a] -> ShowS #
(Eq1 m, Eq a) => Eq (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods (==) :: MaybeT m a -> MaybeT m a -> Bool # (/=) :: MaybeT m a -> MaybeT m a -> Bool #
(Ord1 m, Ord a) => Ord (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods compare :: MaybeT m a -> MaybeT m a -> Ordering # (<) :: MaybeT m a -> MaybeT m a -> Bool # (<=) :: MaybeT m a -> MaybeT m a -> Bool # (>) :: MaybeT m a -> MaybeT m a -> Bool # (>=) :: MaybeT m a -> MaybeT m a -> Bool # max :: MaybeT m a -> MaybeT m a -> MaybeT m a # min :: MaybeT m a -> MaybeT m a -> MaybeT m a #
type Rep1 (MaybeT m :: Type -> Type) |
Instance details Defined in Control.Monad.Trans.Maybe type Rep1 (MaybeT m :: Type -> Type) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.1-inplace" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 Maybe)))
type Rep (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe type Rep (MaybeT m a) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.1-inplace" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Maybe a)))))

liftMaybeT :: Monad m => m a -> MaybeT m a #

tryMaybeT :: IO a -> MaybeT IO a #

Try performing an `IO` action, failing on error.