Agda-2.6.20240714: A dependently typed functional programming language and proof assistant
Safe HaskellNone
LanguageHaskell2010

Agda.Utils.Monad

Synopsis
  • ifM :: Monad m => m Bool -> m a -> m a -> m a
  • unlessM :: Monad m => m Bool -> m () -> m ()
  • guardWithError :: MonadError e m => e -> Bool -> m ()
  • mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
  • tryMaybe :: (MonadError e m, Functor m) => m a -> m (Maybe a)
  • bracket_ :: Monad m => m a -> (a -> m ()) -> m b -> m b
  • finally :: MonadError e m => m a -> m () -> m a
  • tell1 :: (Monoid ws, Singleton w ws, MonadWriter ws m) => w -> m ()
  • concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
  • dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a]
  • (==<<) :: Monad m => (a -> b -> m c) -> (m a, m b) -> m c
  • (<*!>) :: Monad m => m (a -> b) -> m a -> m b
  • whenM :: Monad m => m Bool -> m () -> m ()
  • guardM :: (Monad m, MonadPlus m) => m Bool -> m ()
  • ifNotM :: Monad m => m Bool -> m a -> m a -> m a
  • and2M :: Monad m => m Bool -> m Bool -> m Bool
  • andM :: (Foldable f, Monad m) => f (m Bool) -> m Bool
  • allM :: (Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool
  • or2M :: Monad m => m Bool -> m Bool -> m Bool
  • orM :: (Foldable f, Monad m) => f (m Bool) -> m Bool
  • anyM :: (Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool
  • altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b)
  • orEitherM :: (Monoid e, Monad m, Functor m) => [m (Either e b)] -> m (Either e b)
  • mapM' :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b
  • forM' :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b
  • mapMM :: (Traversable t, Monad m) => (a -> m b) -> m (t a) -> m (t b)
  • forMM :: (Traversable t, Monad m) => m (t a) -> (a -> m b) -> m (t b)
  • mapMM_ :: (Foldable t, Monad m) => (a -> m ()) -> m (t a) -> m ()
  • forMM_ :: (Foldable t, Monad m) => m (t a) -> (a -> m ()) -> m ()
  • mapMaybeMM :: Monad m => (a -> m (Maybe b)) -> m [a] -> m [b]
  • forMaybeM :: Monad m => [a] -> (a -> m (Maybe b)) -> m [b]
  • forMaybeMM :: Monad m => m [a] -> (a -> m (Maybe b)) -> m [b]
  • dropWhileEndM :: Monad m => (a -> m Bool) -> [a] -> m [a]
  • partitionM :: (Functor m, Applicative m) => (a -> m Bool) -> [a] -> m ([a], [a])
  • fromMaybeMP :: MonadPlus m => Maybe a -> m a
  • catMaybesMP :: MonadPlus m => m (Maybe a) -> m a
  • scatterMP :: (MonadPlus m, Foldable t) => m (t a) -> m a
  • tryCatch :: (MonadError e m, Functor m) => m () -> m (Maybe e)
  • localState :: MonadState s m => m a -> m a
  • embedWriter :: forall w (m :: Type -> Type) a. (Monoid w, Monad m) => Writer w a -> WriterT w m a
  • when :: Applicative f => Bool -> f () -> f ()
  • unless :: Applicative f => Bool -> f () -> f ()
  • class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
  • (<$>) :: Functor f => (a -> b) -> f a -> f b
  • (<*>) :: Applicative f => f (a -> b) -> f a -> f b
  • (<$!>) :: Monad m => (a -> b) -> m a -> m b
  • (<$) :: Functor f => a -> f b -> f a

Documentation

ifM :: Monad m => m Bool -> m a -> m a -> m a Source #

Monadic if-then-else.

unlessM :: Monad m => m Bool -> m () -> m () Source #

guardWithError :: MonadError e m => e -> Bool -> m () Source #

Like guard, but raise given error when condition fails.

mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] Source #

A monadic version of mapMaybe :: (a -> Maybe b) -> [a] -> [b].

tryMaybe :: (MonadError e m, Functor m) => m a -> m (Maybe a) Source #

Try a computation, return Nothing if an Error occurs.

bracket_ Source #

Arguments

:: Monad m 
=> m a

Acquires resource. Run first.

-> (a -> m ())

Releases resource. Run last.

-> m b

Computes result. Run in-between.

-> m b 

Bracket without failure. Typically used to preserve state.

finally :: MonadError e m => m a -> m () -> m a Source #

Finally for the Error class. Errors in the finally part take precedence over prior errors.

tell1 :: (Monoid ws, Singleton w ws, MonadWriter ws m) => w -> m () Source #

Output a single value.

concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] Source #

dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a] Source #

A monadic version of dropWhile :: (a -> Bool) -> [a] -> [a].

(==<<) :: Monad m => (a -> b -> m c) -> (m a, m b) -> m c Source #

Binary bind.

(<*!>) :: Monad m => m (a -> b) -> m a -> m b infixl 4 Source #

Strict ap

whenM :: Monad m => m Bool -> m () -> m () Source #

guardM :: (Monad m, MonadPlus m) => m Bool -> m () Source #

Monadic guard.

ifNotM :: Monad m => m Bool -> m a -> m a -> m a Source #

ifNotM mc = ifM (not $ mc)

and2M :: Monad m => m Bool -> m Bool -> m Bool Source #

Lazy monadic conjunction.

andM :: (Foldable f, Monad m) => f (m Bool) -> m Bool Source #

allM :: (Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool Source #

or2M :: Monad m => m Bool -> m Bool -> m Bool Source #

Lazy monadic disjunction.

orM :: (Foldable f, Monad m) => f (m Bool) -> m Bool Source #

anyM :: (Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool Source #

altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b) Source #

Lazy monadic disjunction with Either truth values. Returns the last error message if all fail.

orEitherM :: (Monoid e, Monad m, Functor m) => [m (Either e b)] -> m (Either e b) Source #

Lazy monadic disjunction with accumulation of errors in a monoid. Errors are discarded if we succeed.

mapM' :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b Source #

Generalized version of traverse_ :: Applicative m => (a -> m ()) -> [a] -> m () Executes effects and collects results in left-to-right order. Works best with left-associative monoids.

Note that there is an alternative

mapM' f t = foldr mappend mempty $ mapM f t

that collects results in right-to-left order (effects still left-to-right). It might be preferable for right associative monoids.

forM' :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b Source #

Generalized version of for_ :: Applicative m => [a] -> (a -> m ()) -> m ()

mapMM :: (Traversable t, Monad m) => (a -> m b) -> m (t a) -> m (t b) Source #

forMM :: (Traversable t, Monad m) => m (t a) -> (a -> m b) -> m (t b) Source #

mapMM_ :: (Foldable t, Monad m) => (a -> m ()) -> m (t a) -> m () Source #

forMM_ :: (Foldable t, Monad m) => m (t a) -> (a -> m ()) -> m () Source #

mapMaybeMM :: Monad m => (a -> m (Maybe b)) -> m [a] -> m [b] Source #

A version of mapMaybeM with a computation for the input list.

forMaybeM :: Monad m => [a] -> (a -> m (Maybe b)) -> m [b] Source #

The for version of mapMaybeM.

forMaybeMM :: Monad m => m [a] -> (a -> m (Maybe b)) -> m [b] Source #

The for version of mapMaybeMM.

dropWhileEndM :: Monad m => (a -> m Bool) -> [a] -> m [a] Source #

A monadic version of dropWhileEnd :: (a -> Bool) -> [a] -> m [a]. Effects happen starting at the end of the list until p becomes false.

partitionM :: (Functor m, Applicative m) => (a -> m Bool) -> [a] -> m ([a], [a]) Source #

A `monadic' version of @partition :: (a -> Bool) -> [a] -> ([a],[a])

fromMaybeMP :: MonadPlus m => Maybe a -> m a Source #

Translates Maybe to MonadPlus.

catMaybesMP :: MonadPlus m => m (Maybe a) -> m a Source #

Generalises the catMaybes function from lists to an arbitrary MonadPlus.

scatterMP :: (MonadPlus m, Foldable t) => m (t a) -> m a Source #

Branch over elements of a monadic Foldable data structure.

tryCatch :: (MonadError e m, Functor m) => m () -> m (Maybe e) Source #

Run a command, catch the exception and return it.

localState :: MonadState s m => m a -> m a Source #

Restore state after computation.

embedWriter :: forall w (m :: Type -> Type) a. (Monoid w, Monad m) => Writer w a -> WriterT w m a Source #

when :: Applicative f => Bool -> f () -> f () #

unless :: Applicative f => Bool -> f () -> f () #

class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #

Minimal complete definition

Nothing

Methods

mzero :: m a #

mplus :: m a -> m a -> m a #

Instances

Instances details
MonadPlus NLM Source # 
Instance details

Defined in Agda.TypeChecking.Rewriting.NonLinMatch

Methods

mzero :: NLM a #

mplus :: NLM a -> NLM a -> NLM a #

MonadPlus Get 
Instance details

Defined in Data.Binary.Get.Internal

Methods

mzero :: Get a #

mplus :: Get a -> Get a -> Get a #

MonadPlus Seq 
Instance details

Defined in Data.Sequence.Internal

Methods

mzero :: Seq a #

mplus :: Seq a -> Seq a -> Seq a #

MonadPlus DList 
Instance details

Defined in Data.DList.Internal

Methods

mzero :: DList a #

mplus :: DList a -> DList a -> DList a #

MonadPlus STM 
Instance details

Defined in GHC.Internal.Conc.Sync

Methods

mzero :: STM a #

mplus :: STM a -> STM a -> STM a #

MonadPlus P 
Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

mzero :: P a #

mplus :: P a -> P a -> P a #

MonadPlus ReadP 
Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

mzero :: ReadP a #

mplus :: ReadP a -> ReadP a -> ReadP a #

MonadPlus ReadPrec 
Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadPrec

Methods

mzero :: ReadPrec a #

mplus :: ReadPrec a -> ReadPrec a -> ReadPrec a #

MonadPlus IO 
Instance details

Defined in GHC.Internal.Base

Methods

mzero :: IO a #

mplus :: IO a -> IO a -> IO a #

MonadPlus Array 
Instance details

Defined in Data.Primitive.Array

Methods

mzero :: Array a #

mplus :: Array a -> Array a -> Array a #

MonadPlus SmallArray 
Instance details

Defined in Data.Primitive.SmallArray

Methods

mzero :: SmallArray a #

mplus :: SmallArray a -> SmallArray a -> SmallArray a #

MonadPlus IResult 
Instance details

Defined in Data.Aeson.Types.Internal

Methods

mzero :: IResult a #

mplus :: IResult a -> IResult a -> IResult a #

MonadPlus Parser 
Instance details

Defined in Data.Aeson.Types.Internal

Methods

mzero :: Parser a #

mplus :: Parser a -> Parser a -> Parser a #

MonadPlus Result 
Instance details

Defined in Data.Aeson.Types.Internal

Methods

mzero :: Result a #

mplus :: Result a -> Result a -> Result a #

MonadPlus Vector 
Instance details

Defined in Data.Vector

Methods

mzero :: Vector a #

mplus :: Vector a -> Vector a -> Vector a #

MonadPlus Maybe 
Instance details

Defined in GHC.Internal.Base

Methods

mzero :: Maybe a #

mplus :: Maybe a -> Maybe a -> Maybe a #

MonadPlus [] 
Instance details

Defined in GHC.Internal.Base

Methods

mzero :: [a] #

mplus :: [a] -> [a] -> [a] #

(Functor m, Applicative m, Monad m) => MonadPlus (ListT m) Source # 
Instance details

Defined in Agda.Utils.ListT

Methods

mzero :: ListT m a #

mplus :: ListT m a -> ListT m a -> ListT m a #

Monad m => MonadPlus (CatchT m) 
Instance details

Defined in Control.Monad.Catch.Pure

Methods

mzero :: CatchT m a #

mplus :: CatchT m a -> CatchT m a -> CatchT m a #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) 
Instance details

Defined in GHC.Internal.Control.Arrow

Methods

mzero :: ArrowMonad a a0 #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

MonadPlus (Proxy :: Type -> Type) 
Instance details

Defined in GHC.Internal.Data.Proxy

Methods

mzero :: Proxy a #

mplus :: Proxy a -> Proxy a -> Proxy a #

MonadPlus (U1 :: Type -> Type) 
Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: U1 a #

mplus :: U1 a -> U1 a -> U1 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 #

MonadPlus m => MonadPlus (Kleisli m a) 
Instance details

Defined in GHC.Internal.Control.Arrow

Methods

mzero :: Kleisli m a a0 #

mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

MonadPlus f => MonadPlus (Ap f) 
Instance details

Defined in GHC.Internal.Data.Monoid

Methods

mzero :: Ap f a #

mplus :: Ap f a -> Ap f a -> Ap f a #

MonadPlus f => MonadPlus (Alt f) 
Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

mzero :: Alt f a #

mplus :: Alt f a -> Alt f a -> Alt f a #

MonadPlus f => MonadPlus (Rec1 f) 
Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: Rec1 f a #

mplus :: Rec1 f a -> Rec1 f a -> Rec1 f a #

(Monoid w, Functor m, MonadPlus m) => MonadPlus (AccumT w m) 
Instance details

Defined in Control.Monad.Trans.Accum

Methods

mzero :: AccumT w m a #

mplus :: AccumT w m a -> AccumT w m a -> AccumT w m a #

(Monad m, Monoid e) => MonadPlus (ExceptT e m) 
Instance details

Defined in Control.Monad.Trans.Except

Methods

mzero :: ExceptT e m a #

mplus :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

MonadPlus m => MonadPlus (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

mzero :: IdentityT m a #

mplus :: IdentityT m a -> IdentityT m a -> IdentityT m a #

MonadPlus m => MonadPlus (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mzero :: ReaderT r m a #

mplus :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

MonadPlus m => MonadPlus (SelectT r m) 
Instance details

Defined in Control.Monad.Trans.Select

Methods

mzero :: SelectT r m a #

mplus :: SelectT r m a -> SelectT r m a -> SelectT r m a #

MonadPlus m => MonadPlus (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

MonadPlus m => MonadPlus (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

(Functor m, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

MonadPlus m => MonadPlus (Reverse m) 
Instance details

Defined in Data.Functor.Reverse

Methods

mzero :: Reverse m a #

mplus :: Reverse m a -> Reverse m a -> Reverse m a #

(MonadPlus f, MonadPlus g) => MonadPlus (Product f g) 
Instance details

Defined in Data.Functor.Product

Methods

mzero :: Product f g a #

mplus :: Product f g a -> Product f g a -> Product f g a #

(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) 
Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: (f :*: g) a #

mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #

MonadPlus f => MonadPlus (M1 i c f) 
Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: M1 i c f a #

mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a #

(Functor m, MonadPlus m) => MonadPlus (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.CPS

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(<$>) :: Functor f => (a -> b) -> f a -> f b #

(<*>) :: Applicative f => f (a -> b) -> f a -> f b #

(<$!>) :: Monad m => (a -> b) -> m a -> m b #

(<$) :: Functor f => a -> f b -> f a #