Contents

Description

Utility functions and re-exports for a more ergonomic developing experience. Users themselves will not find much use here.

Synopsis

# Documentation

(++) :: [a] -> [a] -> [a] infixr 5 #

Append two lists, i.e.,

[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]

If the first list is not finite, the result is the first list.

filter :: (a -> Bool) -> [a] -> [a] #

$$\mathcal{O}(n)$$. filter, applied to a predicate and a list, returns the list of those elements that satisfy the predicate; i.e.,

filter p xs = [ x | x <- xs, p x]
>>> filter odd [1, 2, 3]
[1,3]


zip :: [a] -> [b] -> [(a, b)] #

$$\mathcal{O}(\min(m,n))$$. zip takes two lists and returns a list of corresponding pairs.

>>> zip [1, 2] ['a', 'b']
[(1,'a'),(2,'b')]


If one input list is shorter than the other, excess elements of the longer list are discarded, even if one of the lists is infinite:

>>> zip [1] ['a', 'b']
[(1,'a')]
>>> zip [1, 2] ['a']
[(1,'a')]
>>> zip [] [1..]
[]
>>> zip [1..] []
[]


zip is right-lazy:

>>> zip [] undefined
[]
>>> zip undefined []
*** Exception: Prelude.undefined
...


zip is capable of list fusion, but it is restricted to its first list argument and its resulting list.

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
| otherwise = ...

map :: (a -> b) -> [a] -> [b] #

$$\mathcal{O}(n)$$. map f xs is the list obtained by applying f to each element of xs, i.e.,

map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
map f [x1, x2, ...] == [f x1, f x2, ...]
>>> map (+1) [1, 2, 3]
[2,3,4]


($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 # Application operator. This operator is redundant, since ordinary application (f x) means the same as (f$ x). However, $ has low, right-associative binding precedence, so it sometimes allows parentheses to be omitted; for example: f$ g $h x = f (g (h x)) It is also useful in higher-order situations, such as map ($ 0) xs, or zipWith ($) fs xs. Note that ($) is levity-polymorphic in its result type, so that foo $True where foo :: Bool -> Int# is well-typed. guard :: Alternative f => Bool -> f () # Conditional failure of Alternative computations. Defined by guard True = pure () guard False = empty  #### Examples Expand Common uses of guard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in an Alternative-based parser. As an example of signaling an error in the error monad Maybe, consider a safe division function safeDiv x y that returns Nothing when the denominator y is zero and Just (x div y) otherwise. For example: >>> safeDiv 4 0 Nothing  >>> safeDiv 4 2 Just 2  A definition of safeDiv using guards, but not guard: safeDiv :: Int -> Int -> Maybe Int safeDiv x y | y /= 0 = Just (x div y) | otherwise = Nothing  A definition of safeDiv using guard and Monad do-notation: safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x div y)  join :: Monad m => m (m a) -> m a # The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level. 'join bss' can be understood as the do expression do bs <- bss bs  #### Examples Expand A common use of join is to run an IO computation returned from an STM transaction, since STM transactions can't perform IO directly. Recall that atomically :: STM a -> IO a  is used to run STM transactions atomically. So, by specializing the types of atomically and join to atomically :: STM (IO b) -> IO (IO b) join :: IO (IO b) -> IO b  we can compose them as join . atomically :: STM (IO b) -> IO b  to run an STM transaction and the IO action it returns. class Applicative m => Monad (m :: Type -> Type) where # The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following: Left identity return a >>= k = k a Right identity m >>= return = m Associativity m >>= (\x -> k x >>= h) = (m >>= k) >>= h Furthermore, the Monad and Applicative operations should relate as follows: • pure = return • m1 <*> m2 = m1 >>= (x1 -> m2 >>= (x2 -> return (x1 x2))) The above laws imply: • fmap f xs = xs >>= return . f • (>>) = (*>) and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws. Minimal complete definition (>>=) Methods (>>=) :: m a -> (a -> m b) -> m b infixl 1 # Sequentially compose two actions, passing any value produced by the first as an argument to the second. 'as >>= bs' can be understood as the do expression do a <- as bs a  (>>) :: m a -> m b -> m b infixl 1 # Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages. 'as >> bs' can be understood as the do expression do as bs  return :: a -> m a # Inject a value into the monadic type. #### Instances Instances details  Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methods(>>=) :: Complex a -> (a -> Complex b) -> Complex b #(>>) :: Complex a -> Complex b -> Complex b #return :: a -> Complex a # Since: base-4.8.0.0 Instance detailsDefined in Data.Functor.Identity Methods(>>=) :: Identity a -> (a -> Identity b) -> Identity b #(>>) :: Identity a -> Identity b -> Identity b #return :: a -> Identity a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methods(>>=) :: First a -> (a -> First b) -> First b #(>>) :: First a -> First b -> First b #return :: a -> First a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methods(>>=) :: Last a -> (a -> Last b) -> Last b #(>>) :: Last a -> Last b -> Last b #return :: a -> Last a # Since: base-4.11.0.0 Instance detailsDefined in Data.Ord Methods(>>=) :: Down a -> (a -> Down b) -> Down b #(>>) :: Down a -> Down b -> Down b #return :: a -> Down a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods(>>=) :: First a -> (a -> First b) -> First b #(>>) :: First a -> First b -> First b #return :: a -> First a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods(>>=) :: Last a -> (a -> Last b) -> Last b #(>>) :: Last a -> Last b -> Last b #return :: a -> Last a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods(>>=) :: Max a -> (a -> Max b) -> Max b #(>>) :: Max a -> Max b -> Max b #return :: a -> Max a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods(>>=) :: Min a -> (a -> Min b) -> Min b #(>>) :: Min a -> Min b -> Min b #return :: a -> Min a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methods(>>=) :: Dual a -> (a -> Dual b) -> Dual b #(>>) :: Dual a -> Dual b -> Dual b #return :: a -> Dual a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methods(>>=) :: Product a -> (a -> Product b) -> Product b #(>>) :: Product a -> Product b -> Product b #return :: a -> Product a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methods(>>=) :: Sum a -> (a -> Sum b) -> Sum b #(>>) :: Sum a -> Sum b -> Sum b #return :: a -> Sum a # Since: base-4.3.0.0 Instance detailsDefined in GHC.Conc.Sync Methods(>>=) :: STM a -> (a -> STM b) -> STM b #(>>) :: STM a -> STM b -> STM b #return :: a -> STM a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods(>>=) :: Par1 a -> (a -> Par1 b) -> Par1 b #(>>) :: Par1 a -> Par1 b -> Par1 b #return :: a -> Par1 a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methods(>>=) :: P a -> (a -> P b) -> P b #(>>) :: P a -> P b -> P b #return :: a -> P a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methods(>>=) :: ReadP a -> (a -> ReadP b) -> ReadP b #(>>) :: ReadP a -> ReadP b -> ReadP b #return :: a -> ReadP a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadPrec Methods(>>=) :: ReadPrec a -> (a -> ReadPrec b) -> ReadPrec b #(>>) :: ReadPrec a -> ReadPrec b -> ReadPrec b #return :: a -> ReadPrec a # Instance detailsDefined in Data.Sequence.Internal Methods(>>=) :: Seq a -> (a -> Seq b) -> Seq b #(>>) :: Seq a -> Seq b -> Seq b #return :: a -> Seq a # Instance detailsDefined in Data.Tree Methods(>>=) :: Tree a -> (a -> Tree b) -> Tree b #(>>) :: Tree a -> Tree b -> Tree b #return :: a -> Tree a # Since: base-2.1 Instance detailsDefined in GHC.Base Methods(>>=) :: IO a -> (a -> IO b) -> IO b #(>>) :: IO a -> IO b -> IO b #return :: a -> IO a # Instance detailsDefined in Language.Haskell.TH.Syntax Methods(>>=) :: Q a -> (a -> Q b) -> Q b #(>>) :: Q a -> Q b -> Q b #return :: a -> Q a # Instance detailsDefined in XMonad.Core Methods(>>=) :: Query a -> (a -> Query b) -> Query b #(>>) :: Query a -> Query b -> Query b #return :: a -> Query a # Instance detailsDefined in XMonad.Core Methods(>>=) :: X a -> (a -> X b) -> X b #(>>) :: X a -> X b -> X b #return :: a -> X a # Source # Instance detailsDefined in XMonad.Hooks.Focus Methods(>>=) :: FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b #(>>) :: FocusQuery a -> FocusQuery b -> FocusQuery b #return :: a -> FocusQuery a # Source # Instance detailsDefined in XMonad.Util.Parser Methods(>>=) :: Parser a -> (a -> Parser b) -> Parser b #(>>) :: Parser a -> Parser b -> Parser b #return :: a -> Parser a # Source # Instance detailsDefined in XMonad.Util.PureX Methods(>>=) :: PureX a -> (a -> PureX b) -> PureX b #(>>) :: PureX a -> PureX b -> PureX b #return :: a -> PureX a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methods(>>=) :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b #(>>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #return :: a -> NonEmpty a # Since: base-2.1 Instance detailsDefined in GHC.Base Methods(>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b #(>>) :: Maybe a -> Maybe b -> Maybe b #return :: a -> Maybe a # Since: base-4.15 Instance detailsDefined in GHC.Base Methods(>>=) :: Solo a -> (a -> Solo b) -> Solo b #(>>) :: Solo a -> Solo b -> Solo b #return :: a -> Solo a # Monad [] Since: base-2.1 Instance detailsDefined in GHC.Base Methods(>>=) :: [a] -> (a -> [b]) -> [b] #(>>) :: [a] -> [b] -> [b] #return :: a -> [a] # Monad m => Monad (WrappedMonad m) Since: base-4.7.0.0 Instance detailsDefined in Control.Applicative Methods(>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b #(>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b #return :: a -> WrappedMonad m a # ArrowApply a => Monad (ArrowMonad a) Since: base-2.1 Instance detailsDefined in Control.Arrow Methods(>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b #(>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b #return :: a0 -> ArrowMonad a a0 # Monad (Either e) Since: base-4.4.0.0 Instance detailsDefined in Data.Either Methods(>>=) :: Either e a -> (a -> Either e b) -> Either e b #(>>) :: Either e a -> Either e b -> Either e b #return :: a -> Either e a # Monad (Proxy :: Type -> Type) Since: base-4.7.0.0 Instance detailsDefined in Data.Proxy Methods(>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b #(>>) :: Proxy a -> Proxy b -> Proxy b #return :: a -> Proxy a # Monad (U1 :: Type -> Type) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods(>>=) :: U1 a -> (a -> U1 b) -> U1 b #(>>) :: U1 a -> U1 b -> U1 b #return :: a -> U1 a # Monad m => Monad (ListT m) Instance detailsDefined in Control.Monad.Trans.List Methods(>>=) :: ListT m a -> (a -> ListT m b) -> ListT m b #(>>) :: ListT m a -> ListT m b -> ListT m b #return :: a -> ListT m a # Monad m => Monad (MaybeT m) Instance detailsDefined 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 (TwoD a) Source # Instance detailsDefined in XMonad.Actions.GridSelect Methods(>>=) :: TwoD a a0 -> (a0 -> TwoD a b) -> TwoD a b #(>>) :: TwoD a a0 -> TwoD a b -> TwoD a b #return :: a0 -> TwoD a a0 # Monad m => Monad (Invisible m) Source # Instance detailsDefined in XMonad.Util.Invisible Methods(>>=) :: Invisible m a -> (a -> Invisible m b) -> Invisible m b #(>>) :: Invisible m a -> Invisible m b -> Invisible m b #return :: a -> Invisible m a # Source # Instance detailsDefined in XMonad.Util.WindowState Methods(>>=) :: StateQuery s a -> (a -> StateQuery s b) -> StateQuery s b #(>>) :: StateQuery s a -> StateQuery s b -> StateQuery s b #return :: a -> StateQuery s a # Monoid a => Monad ((,) a) Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methods(>>=) :: (a, a0) -> (a0 -> (a, b)) -> (a, b) #(>>) :: (a, a0) -> (a, b) -> (a, b) #return :: a0 -> (a, a0) # Monad m => Monad (Kleisli m a) Since: base-4.14.0.0 Instance detailsDefined in Control.Arrow Methods(>>=) :: Kleisli m a a0 -> (a0 -> Kleisli m a b) -> Kleisli m a b #(>>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b #return :: a0 -> Kleisli m a a0 # Monad f => Monad (Ap f) Since: base-4.12.0.0 Instance detailsDefined in Data.Monoid Methods(>>=) :: Ap f a -> (a -> Ap f b) -> Ap f b #(>>) :: Ap f a -> Ap f b -> Ap f b #return :: a -> Ap f a # Monad f => Monad (Alt f) Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methods(>>=) :: Alt f a -> (a -> Alt f b) -> Alt f b #(>>) :: Alt f a -> Alt f b -> Alt f b #return :: a -> Alt f a # Monad f => Monad (Rec1 f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods(>>=) :: Rec1 f a -> (a -> Rec1 f b) -> Rec1 f b #(>>) :: Rec1 f a -> Rec1 f b -> Rec1 f b #return :: a -> Rec1 f a # (Applicative f, Monad f) => Monad (WhenMissing f x) Equivalent to ReaderT k (ReaderT x (MaybeT f)).Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methods(>>=) :: WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b #(>>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b #return :: a -> WhenMissing f x a # (Monad m, Error e) => Monad (ErrorT e m) Instance detailsDefined in Control.Monad.Trans.Error Methods(>>=) :: ErrorT e m a -> (a -> ErrorT e m b) -> ErrorT e m b #(>>) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m b #return :: a -> ErrorT e m a # Monad m => Monad (ExceptT e m) Instance detailsDefined in Control.Monad.Trans.Except Methods(>>=) :: ExceptT e m a -> (a -> ExceptT e m b) -> ExceptT e m b #(>>) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m b #return :: a -> ExceptT e m a # Monad m => Monad (IdentityT m) Instance detailsDefined in Control.Monad.Trans.Identity Methods(>>=) :: IdentityT m a -> (a -> IdentityT m b) -> IdentityT m b #(>>) :: IdentityT m a -> IdentityT m b -> IdentityT m b #return :: a -> IdentityT m a # Monad m => Monad (ReaderT r m) Instance detailsDefined in Control.Monad.Trans.Reader Methods(>>=) :: ReaderT r m a -> (a -> ReaderT r m b) -> ReaderT r m b #(>>) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m b #return :: a -> ReaderT r m a # Monad m => Monad (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Lazy Methods(>>=) :: StateT s m a -> (a -> StateT s m b) -> StateT s m b #(>>) :: StateT s m a -> StateT s m b -> StateT s m b #return :: a -> StateT s m a # Monad m => Monad (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Strict Methods(>>=) :: StateT s m a -> (a -> StateT s m b) -> StateT s m b #(>>) :: StateT s m a -> StateT s m b -> StateT s m b #return :: a -> StateT s m a # (Monoid w, Monad m) => Monad (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Lazy Methods(>>=) :: WriterT w m a -> (a -> WriterT w m b) -> WriterT w m b #(>>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #return :: a -> WriterT w m a # (Monoid w, Monad m) => Monad (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Strict Methods(>>=) :: WriterT w m a -> (a -> WriterT w m b) -> WriterT w m b #(>>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #return :: a -> WriterT w m a # (Monoid a, Monoid b) => Monad ((,,) a b) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methods(>>=) :: (a, b, a0) -> (a0 -> (a, b, b0)) -> (a, b, b0) #(>>) :: (a, b, a0) -> (a, b, b0) -> (a, b, b0) #return :: a0 -> (a, b, a0) # (Monad f, Monad g) => Monad (Product f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Product Methods(>>=) :: Product f g a -> (a -> Product f g b) -> Product f g b #(>>) :: Product f g a -> Product f g b -> Product f g b #return :: a -> Product f g a # (Monad f, Monad g) => Monad (f :*: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods(>>=) :: (f :*: g) a -> (a -> (f :*: g) b) -> (f :*: g) b #(>>) :: (f :*: g) a -> (f :*: g) b -> (f :*: g) b #return :: a -> (f :*: g) a # (Monad f, Applicative f) => Monad (WhenMatched f x y) Equivalent to ReaderT Key (ReaderT x (ReaderT y (MaybeT f)))Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methods(>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b #(>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b #return :: a -> WhenMatched f x y a # (Applicative f, Monad f) => Monad (WhenMissing f k x) Equivalent to  ReaderT k (ReaderT x (MaybeT f)) .Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methods(>>=) :: WhenMissing f k x a -> (a -> WhenMissing f k x b) -> WhenMissing f k x b #(>>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b #return :: a -> WhenMissing f k x a # Monad (ContT r m) Instance detailsDefined in Control.Monad.Trans.Cont Methods(>>=) :: ContT r m a -> (a -> ContT r m b) -> ContT r m b #(>>) :: ContT r m a -> ContT r m b -> ContT r m b #return :: a -> ContT r m a # (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methods(>>=) :: (a, b, c, a0) -> (a0 -> (a, b, c, b0)) -> (a, b, c, b0) #(>>) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, b0) #return :: a0 -> (a, b, c, a0) # Monad ((->) r) Since: base-2.1 Instance detailsDefined in GHC.Base Methods(>>=) :: (r -> a) -> (a -> r -> b) -> r -> b #(>>) :: (r -> a) -> (r -> b) -> r -> b #return :: a -> r -> a # Monad f => Monad (M1 i c f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods(>>=) :: M1 i c f a -> (a -> M1 i c f b) -> M1 i c f b #(>>) :: M1 i c f a -> M1 i c f b -> M1 i c f b #return :: a -> M1 i c f a # (Monad f, Applicative f) => Monad (WhenMatched f k x y) Equivalent to  ReaderT k (ReaderT x (ReaderT y (MaybeT f))) Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methods(>>=) :: WhenMatched f k x y a -> (a -> WhenMatched f k x y b) -> WhenMatched f k x y b #(>>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b #return :: a -> WhenMatched f k x y a # (Monoid w, Monad m) => Monad (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Lazy Methods(>>=) :: RWST r w s m a -> (a -> RWST r w s m b) -> RWST r w s m b #(>>) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m b #return :: a -> RWST r w s m a # (Monoid w, Monad m) => Monad (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Strict Methods(>>=) :: RWST r w s m a -> (a -> RWST r w s m b) -> RWST r w s m b #(>>) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m b #return :: a -> RWST r w s m a # class Functor (f :: Type -> Type) where # A type f is a Functor if it provides a function fmap which, given any types a and b lets you apply any function from (a -> b) to turn an f a into an f b, preserving the structure of f. Furthermore f needs to adhere to the following: Identity fmap id == id Composition fmap (f . g) == fmap f . fmap g Note, that the second law follows from the free theorem of the type fmap and the first law, so you need only check that the former condition holds. Minimal complete definition fmap Methods fmap :: (a -> b) -> f a -> f b # fmap is used to apply a function of type (a -> b) to a value of type f a, where f is a functor, to produce a value of type f b. Note that for any type constructor with more than one parameter (e.g., Either), only the last type parameter can be modified with fmap (e.g., b in Either a b). Some type constructors with two parameters or more have a Bifunctor instance that allows both the last and the penultimate parameters to be mapped over. #### Examples Expand Convert from a Maybe Int to a Maybe String using show: >>> fmap show Nothing Nothing >>> fmap show (Just 3) Just "3"  Convert from an Either Int Int to an Either Int String using show: >>> fmap show (Left 17) Left 17 >>> fmap show (Right 17) Right "17"  Double each element of a list: >>> fmap (*2) [1,2,3] [2,4,6]  Apply even to the second element of a pair: >>> fmap even (2,2) (2,True)  It may seem surprising that the function is only applied to the last element of the tuple compared to the list example above which applies it to every element in the list. To understand, remember that tuples are type constructors with multiple type parameters: a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over with fmap). It explains why fmap can be used with tuples containing values of different types as in the following example: >>> fmap even ("hello", 1.0, 4) ("hello",1.0,True)  (<$) :: a -> f b -> f a infixl 4 #

Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version.

#### Instances

Instances details
 Since: base-2.1 Instance detailsDefined in Control.Applicative Methodsfmap :: (a -> b) -> ZipList a -> ZipList b #(<$) :: a -> ZipList b -> ZipList a # Since: base-4.6.0.0 Instance detailsDefined in Control.Exception Methodsfmap :: (a -> b) -> Handler a -> Handler b #(<$) :: a -> Handler b -> Handler a # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodsfmap :: (a -> b) -> Complex a -> Complex b #(<$) :: a -> Complex b -> Complex a # Since: base-4.8.0.0 Instance detailsDefined in Data.Functor.Identity Methodsfmap :: (a -> b) -> Identity a -> Identity b #(<$) :: a -> Identity b -> Identity a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methodsfmap :: (a -> b) -> First a -> First b #(<$) :: a -> First b -> First a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methodsfmap :: (a -> b) -> Last a -> Last b #(<$) :: a -> Last b -> Last a # Since: base-4.11.0.0 Instance detailsDefined in Data.Ord Methodsfmap :: (a -> b) -> Down a -> Down b #(<$) :: a -> Down b -> Down a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodsfmap :: (a -> b) -> First a -> First b #(<$) :: a -> First b -> First a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodsfmap :: (a -> b) -> Last a -> Last b #(<$) :: a -> Last b -> Last a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodsfmap :: (a -> b) -> Max a -> Max b #(<$) :: a -> Max b -> Max a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodsfmap :: (a -> b) -> Min a -> Min b #(<$) :: a -> Min b -> Min a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Dual a -> Dual b #(<$) :: a -> Dual b -> Dual a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Product a -> Product b #(<$) :: a -> Product b -> Product a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Sum a -> Sum b #(<$) :: a -> Sum b -> Sum a # Since: base-4.3.0.0 Instance detailsDefined in GHC.Conc.Sync Methodsfmap :: (a -> b) -> STM a -> STM b #(<$) :: a -> STM b -> STM a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> Par1 a -> Par1 b #(<$) :: a -> Par1 b -> Par1 a # Since: base-4.8.0.0 Instance detailsDefined in Text.ParserCombinators.ReadP Methodsfmap :: (a -> b) -> P a -> P b #(<$) :: a -> P b -> P a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methodsfmap :: (a -> b) -> ReadP a -> ReadP b #(<$) :: a -> ReadP b -> ReadP a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadPrec Methodsfmap :: (a -> b) -> ReadPrec a -> ReadPrec b #(<$) :: a -> ReadPrec b -> ReadPrec a # Instance detailsDefined in Data.IntMap.Internal Methodsfmap :: (a -> b) -> IntMap a -> IntMap b #(<$) :: a -> IntMap b -> IntMap a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> Digit a -> Digit b #(<$) :: a -> Digit b -> Digit a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> Elem a -> Elem b #(<$) :: a -> Elem b -> Elem a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> FingerTree a -> FingerTree b #(<$) :: a -> FingerTree b -> FingerTree a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> Node a -> Node b #(<$) :: a -> Node b -> Node a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> Seq a -> Seq b #(<$) :: a -> Seq b -> Seq a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> ViewL a -> ViewL b #(<$) :: a -> ViewL b -> ViewL a # Instance detailsDefined in Data.Sequence.Internal Methodsfmap :: (a -> b) -> ViewR a -> ViewR b #(<$) :: a -> ViewR b -> ViewR a # Instance detailsDefined in Data.Tree Methodsfmap :: (a -> b) -> Tree a -> Tree b #(<$) :: a -> Tree b -> Tree a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> IO a -> IO b #(<$) :: a -> IO b -> IO a # Instance detailsDefined in Language.Haskell.TH.Syntax Methodsfmap :: (a -> b) -> Q a -> Q b #(<$) :: a -> Q b -> Q a # Instance detailsDefined in Language.Haskell.TH.Syntax Methodsfmap :: (a -> b) -> TyVarBndr a -> TyVarBndr b #(<$) :: a -> TyVarBndr b -> TyVarBndr a # Instance detailsDefined in XMonad.Core Methodsfmap :: (a -> b) -> Directories' a -> Directories' b #(<$) :: a -> Directories' b -> Directories' a # Instance detailsDefined in XMonad.Core Methodsfmap :: (a -> b) -> Query a -> Query b #(<$) :: a -> Query b -> Query a # Instance detailsDefined in XMonad.Core Methodsfmap :: (a -> b) -> X a -> X b #(<$) :: a -> X b -> X a # Instance detailsDefined in XMonad.StackSet Methodsfmap :: (a -> b) -> Stack a -> Stack b #(<$) :: a -> Stack b -> Stack a # Source # Instance detailsDefined in XMonad.Actions.WorkspaceCursors Methodsfmap :: (a -> b) -> Cursors a -> Cursors b #(<$) :: a -> Cursors b -> Cursors a # Source # Instance detailsDefined in XMonad.Hooks.Focus Methodsfmap :: (a -> b) -> FocusQuery a -> FocusQuery b #(<$) :: a -> FocusQuery b -> FocusQuery a # Source # Instance detailsDefined in XMonad.Prelude Methodsfmap :: (a -> b) -> Stream a -> Stream b #(<$) :: a -> Stream b -> Stream a # Source # Instance detailsDefined in XMonad.Util.Parser Methodsfmap :: (a -> b) -> Parser a -> Parser b #(<$) :: a -> Parser b -> Parser a # Source # Instance detailsDefined in XMonad.Util.PureX Methodsfmap :: (a -> b) -> PureX a -> PureX b #(<$) :: a -> PureX b -> PureX a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> NonEmpty a -> NonEmpty b #(<$) :: a -> NonEmpty b -> NonEmpty a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> Maybe a -> Maybe b #(<$) :: a -> Maybe b -> Maybe a # Since: base-4.15 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> Solo a -> Solo b #(<$) :: a -> Solo b -> Solo a # Functor [] Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> [a] -> [b] #(<$) :: a -> [b] -> [a] # Monad m => Functor (WrappedMonad m) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodsfmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b #(<$) :: a -> WrappedMonad m b -> WrappedMonad m a # Arrow a => Functor (ArrowMonad a) Since: base-4.6.0.0 Instance detailsDefined in Control.Arrow Methodsfmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # Since: base-3.0 Instance detailsDefined in Data.Either Methodsfmap :: (a0 -> b) -> Either a a0 -> Either a b #(<$) :: a0 -> Either a b -> Either a a0 # Functor (StateL s) Since: base-4.0 Instance detailsDefined in Data.Functor.Utils Methodsfmap :: (a -> b) -> StateL s a -> StateL s b #(<$) :: a -> StateL s b -> StateL s a # Functor (StateR s) Since: base-4.0 Instance detailsDefined in Data.Functor.Utils Methodsfmap :: (a -> b) -> StateR s a -> StateR s b #(<$) :: a -> StateR s b -> StateR s a # Functor (Proxy :: Type -> Type) Since: base-4.7.0.0 Instance detailsDefined in Data.Proxy Methodsfmap :: (a -> b) -> Proxy a -> Proxy b #(<$) :: a -> Proxy b -> Proxy a # Functor (Arg a) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodsfmap :: (a0 -> b) -> Arg a a0 -> Arg a b #(<$) :: a0 -> Arg a b -> Arg a a0 # Functor (Array i) Since: base-2.1 Instance detailsDefined in GHC.Arr Methodsfmap :: (a -> b) -> Array i a -> Array i b #(<$) :: a -> Array i b -> Array i a # Functor (U1 :: Type -> Type) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> U1 a -> U1 b #(<$) :: a -> U1 b -> U1 a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> V1 a -> V1 b #(<$) :: a -> V1 b -> V1 a # Functor (Map k) Instance detailsDefined in Data.Map.Internal Methodsfmap :: (a -> b) -> Map k a -> Map k b #(<$) :: a -> Map k b -> Map k a # Functor m => Functor (ListT m) Instance detailsDefined in Control.Monad.Trans.List Methodsfmap :: (a -> b) -> ListT m a -> ListT m b #(<$) :: a -> ListT m b -> ListT m a # Functor m => Functor (MaybeT m) Instance detailsDefined in Control.Monad.Trans.Maybe Methodsfmap :: (a -> b) -> MaybeT m a -> MaybeT m b #(<$) :: a -> MaybeT m b -> MaybeT m a # Functor (TwoD a) Source # Instance detailsDefined in XMonad.Actions.GridSelect Methodsfmap :: (a0 -> b) -> TwoD a a0 -> TwoD a b #(<$) :: a0 -> TwoD a b -> TwoD a a0 # Source # Instance detailsDefined in XMonad.Util.History Methodsfmap :: (a -> b) -> History k a -> History k b #(<$) :: a -> History k b -> History k a # Functor m => Functor (Invisible m) Source # Instance detailsDefined in XMonad.Util.Invisible Methodsfmap :: (a -> b) -> Invisible m a -> Invisible m b #(<$) :: a -> Invisible m b -> Invisible m a # Source # Instance detailsDefined in XMonad.Util.WindowState Methodsfmap :: (a -> b) -> StateQuery s a -> StateQuery s b #(<$) :: a -> StateQuery s b -> StateQuery s a # Functor ((,) a) Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a0 -> b) -> (a, a0) -> (a, b) #(<$) :: a0 -> (a, b) -> (a, a0) # Arrow a => Functor (WrappedArrow a b) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodsfmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 #(<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # Functor m => Functor (Kleisli m a) Since: base-4.14.0.0 Instance detailsDefined in Control.Arrow Methodsfmap :: (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b #(<$) :: a0 -> Kleisli m a b -> Kleisli m a a0 # Functor (Const m :: Type -> Type) Since: base-2.1 Instance detailsDefined in Data.Functor.Const Methodsfmap :: (a -> b) -> Const m a -> Const m b #(<$) :: a -> Const m b -> Const m a # Functor f => Functor (Ap f) Since: base-4.12.0.0 Instance detailsDefined in Data.Monoid Methodsfmap :: (a -> b) -> Ap f a -> Ap f b #(<$) :: a -> Ap f b -> Ap f a # Functor f => Functor (Alt f) Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Alt f a -> Alt f b #(<$) :: a -> Alt f b -> Alt f a # Functor f => Functor (Rec1 f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> Rec1 f a -> Rec1 f b #(<$) :: a -> Rec1 f b -> Rec1 f a # Functor (URec (Ptr ()) :: TYPE LiftedRep -> Type) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec (Ptr ()) a -> URec (Ptr ()) b #(<$) :: a -> URec (Ptr ()) b -> URec (Ptr ()) a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Char a -> URec Char b #(<$) :: a -> URec Char b -> URec Char a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Double a -> URec Double b #(<$) :: a -> URec Double b -> URec Double a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Float a -> URec Float b #(<$) :: a -> URec Float b -> URec Float a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Int a -> URec Int b #(<$) :: a -> URec Int b -> URec Int a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Word a -> URec Word b #(<$) :: a -> URec Word b -> URec Word a # (Applicative f, Monad f) => Functor (WhenMissing f x) Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methodsfmap :: (a -> b) -> WhenMissing f x a -> WhenMissing f x b #(<$) :: a -> WhenMissing f x b -> WhenMissing f x a # Functor m => Functor (ErrorT e m) Instance detailsDefined in Control.Monad.Trans.Error Methodsfmap :: (a -> b) -> ErrorT e m a -> ErrorT e m b #(<$) :: a -> ErrorT e m b -> ErrorT e m a # Functor m => Functor (ExceptT e m) Instance detailsDefined in Control.Monad.Trans.Except Methodsfmap :: (a -> b) -> ExceptT e m a -> ExceptT e m b #(<$) :: a -> ExceptT e m b -> ExceptT e m a # Functor m => Functor (IdentityT m) Instance detailsDefined in Control.Monad.Trans.Identity Methodsfmap :: (a -> b) -> IdentityT m a -> IdentityT m b #(<$) :: a -> IdentityT m b -> IdentityT m a # Functor m => Functor (ReaderT r m) Instance detailsDefined in Control.Monad.Trans.Reader Methodsfmap :: (a -> b) -> ReaderT r m a -> ReaderT r m b #(<$) :: a -> ReaderT r m b -> ReaderT r m a # Functor m => Functor (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Lazy Methodsfmap :: (a -> b) -> StateT s m a -> StateT s m b #(<$) :: a -> StateT s m b -> StateT s m a # Functor m => Functor (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Strict Methodsfmap :: (a -> b) -> StateT s m a -> StateT s m b #(<$) :: a -> StateT s m b -> StateT s m a # Functor m => Functor (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Lazy Methodsfmap :: (a -> b) -> WriterT w m a -> WriterT w m b #(<$) :: a -> WriterT w m b -> WriterT w m a # Functor m => Functor (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Strict Methodsfmap :: (a -> b) -> WriterT w m a -> WriterT w m b #(<$) :: a -> WriterT w m b -> WriterT w m a # Functor ((,,) a b) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methodsfmap :: (a0 -> b0) -> (a, b, a0) -> (a, b, b0) #(<$) :: a0 -> (a, b, b0) -> (a, b, a0) # (Functor f, Functor g) => Functor (Product f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Product Methodsfmap :: (a -> b) -> Product f g a -> Product f g b #(<$) :: a -> Product f g b -> Product f g a # (Functor f, Functor g) => Functor (Sum f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Sum Methodsfmap :: (a -> b) -> Sum f g a -> Sum f g b #(<$) :: a -> Sum f g b -> Sum f g a # (Functor f, Functor g) => Functor (f :*: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :*: g) a -> (f :*: g) b #(<$) :: a -> (f :*: g) b -> (f :*: g) a # (Functor f, Functor g) => Functor (f :+: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :+: g) a -> (f :+: g) b #(<$) :: a -> (f :+: g) b -> (f :+: g) a # Functor (K1 i c :: TYPE LiftedRep -> Type) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> K1 i c a -> K1 i c b #(<$) :: a -> K1 i c b -> K1 i c a # Functor f => Functor (WhenMatched f x y) Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methodsfmap :: (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b #(<$) :: a -> WhenMatched f x y b -> WhenMatched f x y a # (Applicative f, Monad f) => Functor (WhenMissing f k x) Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methodsfmap :: (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b #(<$) :: a -> WhenMissing f k x b -> WhenMissing f k x a # Functor (ContT r m) Instance detailsDefined in Control.Monad.Trans.Cont Methodsfmap :: (a -> b) -> ContT r m a -> ContT r m b #(<$) :: a -> ContT r m b -> ContT r m a # Functor ((,,,) a b c) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methodsfmap :: (a0 -> b0) -> (a, b, c, a0) -> (a, b, c, b0) #(<$) :: a0 -> (a, b, c, b0) -> (a, b, c, a0) # Functor ((->) r) Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> (r -> a) -> r -> b #(<$) :: a -> (r -> b) -> r -> a # (Functor f, Functor g) => Functor (Compose f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Compose Methodsfmap :: (a -> b) -> Compose f g a -> Compose f g b #(<$) :: a -> Compose f g b -> Compose f g a # (Functor f, Functor g) => Functor (f :.: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :.: g) a -> (f :.: g) b #(<$) :: a -> (f :.: g) b -> (f :.: g) a # Functor f => Functor (M1 i c f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> M1 i c f a -> M1 i c f b #(<$) :: a -> M1 i c f b -> M1 i c f a # Functor f => Functor (WhenMatched f k x y) Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methodsfmap :: (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b #(<$) :: a -> WhenMatched f k x y b -> WhenMatched f k x y a # Functor m => Functor (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Lazy Methodsfmap :: (a -> b) -> RWST r w s m a -> RWST r w s m b #(<$) :: a -> RWST r w s m b -> RWST r w s m a # Functor m => Functor (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Strict Methodsfmap :: (a -> b) -> RWST r w s m a -> RWST r w s m b #(<$) :: a -> RWST r w s m b -> RWST r w s m a #

class Monad m => MonadFail (m :: Type -> Type) where #

When a value is bound in do-notation, the pattern on the left hand side of <- might not match. In this case, this class provides a function to recover.

A Monad without a MonadFail instance may only be used in conjunction with pattern that always match, such as newtypes, tuples, data types with only a single data constructor, and irrefutable patterns (~pat).

Instances of MonadFail should satisfy the following law: fail s should be a left zero for >>=,

fail s >>= f  =  fail s


If your Monad is also MonadPlus, a popular definition is

fail _ = mzero


Since: base-4.9.0.0

Methods

fail :: String -> m a #

#### Instances

Instances details

class Functor f => Applicative (f :: Type -> Type) where #

A functor with application, providing operations to

• embed pure expressions (pure), and
• sequence computations and combine their results (<*> and liftA2).

A minimal complete definition must include implementations of pure and of either <*> or liftA2. If it defines both, then they must behave the same as their default definitions:

(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> y Further, any definition must satisfy the following: Identity pure id <*> v = v Composition pure (.) <*> u <*> v <*> w = u <*> (v <*> w) Homomorphism pure f <*> pure x = pure (f x) Interchange u <*> pure y = pure ($ y) <*> u

The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:

• u *> v = (id <$ u) <*> v • u <* v = liftA2 const u v As a consequence of these laws, the Functor instance for f will satisfy • fmap f x = pure f <*> x It may be useful to note that supposing forall x y. p (q x y) = f x . g y it follows from the above that liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v If f is also a Monad, it should satisfy • pure = return • m1 <*> m2 = m1 >>= (x1 -> m2 >>= (x2 -> return (x1 x2))) • (*>) = (>>) (which implies that pure and <*> satisfy the applicative functor laws). Minimal complete definition pure, ((<*>) | liftA2) Methods pure :: a -> f a # Lift a value. (<*>) :: f (a -> b) -> f a -> f b infixl 4 # Sequential application. A few functors support an implementation of <*> that is more efficient than the default one. #### Example Expand Used in combination with (<$>), (<*>) can be used to build a record.

>>> data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}

>>> produceFoo :: Applicative f => f Foo

>>> produceBar :: Applicative f => f Bar
>>> produceBaz :: Applicative f => f Baz

>>> mkState :: Applicative f => f MyState
>>> mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz  liftA2 :: (a -> b -> c) -> f a -> f b -> f c # Lift a binary function to actions. Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>. This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap. #### Example Expand >>> liftA2 (,) (Just 3) (Just 5) Just (3,5)  (*>) :: f a -> f b -> f b infixl 4 # Sequence actions, discarding the value of the first argument. #### Examples Expand If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing. >>> Just 2 *> Just 3 Just 3  >>> Nothing *> Just 3 Nothing  Of course a more interesting use case would be to have effectful computations instead of just returning pure values. >>> import Data.Char >>> import Text.ParserCombinators.ReadP >>> let p = string "my name is " *> munch1 isAlpha <* eof >>> readP_to_S p "my name is Simon" [("Simon","")]  (<*) :: f a -> f b -> f a infixl 4 # Sequence actions, discarding the value of the second argument. #### Instances Instances details  f <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN)where zipWithN refers to the zipWith function of the appropriate arity (zipWith, zipWith3, zipWith4, ...). For example:(\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]}Since: base-2.1 Instance detailsDefined in Control.Applicative Methodspure :: a -> ZipList a #(<*>) :: ZipList (a -> b) -> ZipList a -> ZipList b #liftA2 :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c #(*>) :: ZipList a -> ZipList b -> ZipList b #(<*) :: ZipList a -> ZipList b -> ZipList a # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodspure :: a -> Complex a #(<*>) :: Complex (a -> b) -> Complex a -> Complex b #liftA2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c #(*>) :: Complex a -> Complex b -> Complex b #(<*) :: Complex a -> Complex b -> Complex a # Since: base-4.8.0.0 Instance detailsDefined in Data.Functor.Identity Methodspure :: a -> Identity a #(<*>) :: Identity (a -> b) -> Identity a -> Identity b #liftA2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c #(*>) :: Identity a -> Identity b -> Identity b #(<*) :: Identity a -> Identity b -> Identity a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methodspure :: a -> First a #(<*>) :: First (a -> b) -> First a -> First b #liftA2 :: (a -> b -> c) -> First a -> First b -> First c #(*>) :: First a -> First b -> First b #(<*) :: First a -> First b -> First a # Since: base-4.8.0.0 Instance detailsDefined in Data.Monoid Methodspure :: a -> Last a #(<*>) :: Last (a -> b) -> Last a -> Last b #liftA2 :: (a -> b -> c) -> Last a -> Last b -> Last c #(*>) :: Last a -> Last b -> Last b #(<*) :: Last a -> Last b -> Last a # Since: base-4.11.0.0 Instance detailsDefined in Data.Ord Methodspure :: a -> Down a #(<*>) :: Down (a -> b) -> Down a -> Down b #liftA2 :: (a -> b -> c) -> Down a -> Down b -> Down c #(*>) :: Down a -> Down b -> Down b #(<*) :: Down a -> Down b -> Down a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodspure :: a -> First a #(<*>) :: First (a -> b) -> First a -> First b #liftA2 :: (a -> b -> c) -> First a -> First b -> First c #(*>) :: First a -> First b -> First b #(<*) :: First a -> First b -> First a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodspure :: a -> Last a #(<*>) :: Last (a -> b) -> Last a -> Last b #liftA2 :: (a -> b -> c) -> Last a -> Last b -> Last c #(*>) :: Last a -> Last b -> Last b #(<*) :: Last a -> Last b -> Last a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodspure :: a -> Max a #(<*>) :: Max (a -> b) -> Max a -> Max b #liftA2 :: (a -> b -> c) -> Max a -> Max b -> Max c #(*>) :: Max a -> Max b -> Max b #(<*) :: Max a -> Max b -> Max a # Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methodspure :: a -> Min a #(<*>) :: Min (a -> b) -> Min a -> Min b #liftA2 :: (a -> b -> c) -> Min a -> Min b -> Min c #(*>) :: Min a -> Min b -> Min b #(<*) :: Min a -> Min b -> Min a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodspure :: a -> Dual a #(<*>) :: Dual (a -> b) -> Dual a -> Dual b #liftA2 :: (a -> b -> c) -> Dual a -> Dual b -> Dual c #(*>) :: Dual a -> Dual b -> Dual b #(<*) :: Dual a -> Dual b -> Dual a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodspure :: a -> Product a #(<*>) :: Product (a -> b) -> Product a -> Product b #liftA2 :: (a -> b -> c) -> Product a -> Product b -> Product c #(*>) :: Product a -> Product b -> Product b #(<*) :: Product a -> Product b -> Product a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodspure :: a -> Sum a #(<*>) :: Sum (a -> b) -> Sum a -> Sum b #liftA2 :: (a -> b -> c) -> Sum a -> Sum b -> Sum c #(*>) :: Sum a -> Sum b -> Sum b #(<*) :: Sum a -> Sum b -> Sum a # Since: base-4.8.0.0 Instance detailsDefined in GHC.Conc.Sync Methodspure :: a -> STM a #(<*>) :: STM (a -> b) -> STM a -> STM b #liftA2 :: (a -> b -> c) -> STM a -> STM b -> STM c #(*>) :: STM a -> STM b -> STM b #(<*) :: STM a -> STM b -> STM a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> Par1 a #(<*>) :: Par1 (a -> b) -> Par1 a -> Par1 b #liftA2 :: (a -> b -> c) -> Par1 a -> Par1 b -> Par1 c #(*>) :: Par1 a -> Par1 b -> Par1 b #(<*) :: Par1 a -> Par1 b -> Par1 a # Since: base-4.5.0.0 Instance detailsDefined in Text.ParserCombinators.ReadP Methodspure :: a -> P a #(<*>) :: P (a -> b) -> P a -> P b #liftA2 :: (a -> b -> c) -> P a -> P b -> P c #(*>) :: P a -> P b -> P b #(<*) :: P a -> P b -> P a # Since: base-4.6.0.0 Instance detailsDefined in Text.ParserCombinators.ReadP Methodspure :: a -> ReadP a #(<*>) :: ReadP (a -> b) -> ReadP a -> ReadP b #liftA2 :: (a -> b -> c) -> ReadP a -> ReadP b -> ReadP c #(*>) :: ReadP a -> ReadP b -> ReadP b #(<*) :: ReadP a -> ReadP b -> ReadP a # Since: base-4.6.0.0 Instance detailsDefined in Text.ParserCombinators.ReadPrec Methodspure :: a -> ReadPrec a #(<*>) :: ReadPrec (a -> b) -> ReadPrec a -> ReadPrec b #liftA2 :: (a -> b -> c) -> ReadPrec a -> ReadPrec b -> ReadPrec c #(*>) :: ReadPrec a -> ReadPrec b -> ReadPrec b #(<*) :: ReadPrec a -> ReadPrec b -> ReadPrec a # Since: containers-0.5.4 Instance detailsDefined in Data.Sequence.Internal Methodspure :: a -> Seq a #(<*>) :: Seq (a -> b) -> Seq a -> Seq b #liftA2 :: (a -> b -> c) -> Seq a -> Seq b -> Seq c #(*>) :: Seq a -> Seq b -> Seq b #(<*) :: Seq a -> Seq b -> Seq a # Instance detailsDefined in Data.Tree Methodspure :: a -> Tree a #(<*>) :: Tree (a -> b) -> Tree a -> Tree b #liftA2 :: (a -> b -> c) -> Tree a -> Tree b -> Tree c #(*>) :: Tree a -> Tree b -> Tree b #(<*) :: Tree a -> Tree b -> Tree a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodspure :: a -> IO a #(<*>) :: IO (a -> b) -> IO a -> IO b #liftA2 :: (a -> b -> c) -> IO a -> IO b -> IO c #(*>) :: IO a -> IO b -> IO b #(<*) :: IO a -> IO b -> IO a # Instance detailsDefined in Language.Haskell.TH.Syntax Methodspure :: a -> Q a #(<*>) :: Q (a -> b) -> Q a -> Q b #liftA2 :: (a -> b -> c) -> Q a -> Q b -> Q c #(*>) :: Q a -> Q b -> Q b #(<*) :: Q a -> Q b -> Q a # Instance detailsDefined in XMonad.Core Methodspure :: a -> Query a #(<*>) :: Query (a -> b) -> Query a -> Query b #liftA2 :: (a -> b -> c) -> Query a -> Query b -> Query c #(*>) :: Query a -> Query b -> Query b #(<*) :: Query a -> Query b -> Query a # Instance detailsDefined in XMonad.Core Methodspure :: a -> X a #(<*>) :: X (a -> b) -> X a -> X b #liftA2 :: (a -> b -> c) -> X a -> X b -> X c #(*>) :: X a -> X b -> X b #(<*) :: X a -> X b -> X a # Source # Instance detailsDefined in XMonad.Hooks.Focus Methodspure :: a -> FocusQuery a #(<*>) :: FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b #liftA2 :: (a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c #(*>) :: FocusQuery a -> FocusQuery b -> FocusQuery b #(<*) :: FocusQuery a -> FocusQuery b -> FocusQuery a # Source # Instance detailsDefined in XMonad.Util.Parser Methodspure :: a -> Parser a #(<*>) :: Parser (a -> b) -> Parser a -> Parser b #liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c #(*>) :: Parser a -> Parser b -> Parser b #(<*) :: Parser a -> Parser b -> Parser a # Source # Instance detailsDefined in XMonad.Util.PureX Methodspure :: a -> PureX a #(<*>) :: PureX (a -> b) -> PureX a -> PureX b #liftA2 :: (a -> b -> c) -> PureX a -> PureX b -> PureX c #(*>) :: PureX a -> PureX b -> PureX b #(<*) :: PureX a -> PureX b -> PureX a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodspure :: a -> NonEmpty a #(<*>) :: NonEmpty (a -> b) -> NonEmpty a -> NonEmpty b #liftA2 :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c #(*>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #(<*) :: NonEmpty a -> NonEmpty b -> NonEmpty a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodspure :: a -> Maybe a #(<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b #liftA2 :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c #(*>) :: Maybe a -> Maybe b -> Maybe b #(<*) :: Maybe a -> Maybe b -> Maybe a # Since: base-4.15 Instance detailsDefined in GHC.Base Methodspure :: a -> Solo a #(<*>) :: Solo (a -> b) -> Solo a -> Solo b #liftA2 :: (a -> b -> c) -> Solo a -> Solo b -> Solo c #(*>) :: Solo a -> Solo b -> Solo b #(<*) :: Solo a -> Solo b -> Solo a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodspure :: a -> [a] #(<*>) :: [a -> b] -> [a] -> [b] #liftA2 :: (a -> b -> c) -> [a] -> [b] -> [c] #(*>) :: [a] -> [b] -> [b] #(<*) :: [a] -> [b] -> [a] # Monad m => Applicative (WrappedMonad m) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodspure :: a -> WrappedMonad m a #(<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b #liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c #(*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b #(<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # Arrow a => Applicative (ArrowMonad a) Since: base-4.6.0.0 Instance detailsDefined in Control.Arrow Methodspure :: a0 -> ArrowMonad a a0 #(<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c #(*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b #(<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # Since: base-3.0 Instance detailsDefined in Data.Either Methodspure :: a -> Either e a #(<*>) :: Either e (a -> b) -> Either e a -> Either e b #liftA2 :: (a -> b -> c) -> Either e a -> Either e b -> Either e c #(*>) :: Either e a -> Either e b -> Either e b #(<*) :: Either e a -> Either e b -> Either e a # Applicative (StateL s) Since: base-4.0 Instance detailsDefined in Data.Functor.Utils Methodspure :: a -> StateL s a #(<*>) :: StateL s (a -> b) -> StateL s a -> StateL s b #liftA2 :: (a -> b -> c) -> StateL s a -> StateL s b -> StateL s c #(*>) :: StateL s a -> StateL s b -> StateL s b #(<*) :: StateL s a -> StateL s b -> StateL s a # Applicative (StateR s) Since: base-4.0 Instance detailsDefined in Data.Functor.Utils Methodspure :: a -> StateR s a #(<*>) :: StateR s (a -> b) -> StateR s a -> StateR s b #liftA2 :: (a -> b -> c) -> StateR s a -> StateR s b -> StateR s c #(*>) :: StateR s a -> StateR s b -> StateR s b #(<*) :: StateR s a -> StateR s b -> StateR s a # Applicative (Proxy :: Type -> Type) Since: base-4.7.0.0 Instance detailsDefined in Data.Proxy Methodspure :: a -> Proxy a #(<*>) :: Proxy (a -> b) -> Proxy a -> Proxy b #liftA2 :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c #(*>) :: Proxy a -> Proxy b -> Proxy b #(<*) :: Proxy a -> Proxy b -> Proxy a # Applicative (U1 :: Type -> Type) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> U1 a #(<*>) :: U1 (a -> b) -> U1 a -> U1 b #liftA2 :: (a -> b -> c) -> U1 a -> U1 b -> U1 c #(*>) :: U1 a -> U1 b -> U1 b #(<*) :: U1 a -> U1 b -> U1 a # Applicative m => Applicative (ListT m) Instance detailsDefined in Control.Monad.Trans.List Methodspure :: a -> ListT m a #(<*>) :: ListT m (a -> b) -> ListT m a -> ListT m b #liftA2 :: (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c #(*>) :: ListT m a -> ListT m b -> ListT m b #(<*) :: ListT m a -> ListT m b -> ListT m a # (Functor m, Monad m) => Applicative (MaybeT m) Instance detailsDefined in Control.Monad.Trans.Maybe Methodspure :: 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 # Source # Instance detailsDefined in XMonad.Actions.GridSelect Methodspure :: a0 -> TwoD a a0 #(<*>) :: TwoD a (a0 -> b) -> TwoD a a0 -> TwoD a b #liftA2 :: (a0 -> b -> c) -> TwoD a a0 -> TwoD a b -> TwoD a c #(*>) :: TwoD a a0 -> TwoD a b -> TwoD a b #(<*) :: TwoD a a0 -> TwoD a b -> TwoD a a0 # Source # Instance detailsDefined in XMonad.Util.Invisible Methodspure :: a -> Invisible m a #(<*>) :: Invisible m (a -> b) -> Invisible m a -> Invisible m b #liftA2 :: (a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c #(*>) :: Invisible m a -> Invisible m b -> Invisible m b #(<*) :: Invisible m a -> Invisible m b -> Invisible m a # Source # Instance detailsDefined in XMonad.Util.WindowState Methodspure :: a -> StateQuery s a #(<*>) :: StateQuery s (a -> b) -> StateQuery s a -> StateQuery s b #liftA2 :: (a -> b -> c) -> StateQuery s a -> StateQuery s b -> StateQuery s c #(*>) :: StateQuery s a -> StateQuery s b -> StateQuery s b #(<*) :: StateQuery s a -> StateQuery s b -> StateQuery s a # Monoid a => Applicative ((,) a) For tuples, the Monoid constraint on a determines how the first values merge. For example, Strings concatenate:("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017)Since: base-2.1 Instance detailsDefined in GHC.Base Methodspure :: a0 -> (a, a0) #(<*>) :: (a, a0 -> b) -> (a, a0) -> (a, b) #liftA2 :: (a0 -> b -> c) -> (a, a0) -> (a, b) -> (a, c) #(*>) :: (a, a0) -> (a, b) -> (a, b) #(<*) :: (a, a0) -> (a, b) -> (a, a0) # Arrow a => Applicative (WrappedArrow a b) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodspure :: a0 -> WrappedArrow a b a0 #(<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 #liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c #(*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 #(<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # Applicative m => Applicative (Kleisli m a) Since: base-4.14.0.0 Instance detailsDefined in Control.Arrow Methodspure :: a0 -> Kleisli m a a0 #(<*>) :: Kleisli m a (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b #liftA2 :: (a0 -> b -> c) -> Kleisli m a a0 -> Kleisli m a b -> Kleisli m a c #(*>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b #(<*) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a a0 # Monoid m => Applicative (Const m :: Type -> Type) Since: base-2.0.1 Instance detailsDefined in Data.Functor.Const Methodspure :: a -> Const m a #(<*>) :: Const m (a -> b) -> Const m a -> Const m b #liftA2 :: (a -> b -> c) -> Const m a -> Const m b -> Const m c #(*>) :: Const m a -> Const m b -> Const m b #(<*) :: Const m a -> Const m b -> Const m a # Applicative f => Applicative (Ap f) Since: base-4.12.0.0 Instance detailsDefined in Data.Monoid Methodspure :: a -> Ap f a #(<*>) :: Ap f (a -> b) -> Ap f a -> Ap f b #liftA2 :: (a -> b -> c) -> Ap f a -> Ap f b -> Ap f c #(*>) :: Ap f a -> Ap f b -> Ap f b #(<*) :: Ap f a -> Ap f b -> Ap f a # Applicative f => Applicative (Alt f) Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodspure :: a -> Alt f a #(<*>) :: Alt f (a -> b) -> Alt f a -> Alt f b #liftA2 :: (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c #(*>) :: Alt f a -> Alt f b -> Alt f b #(<*) :: Alt f a -> Alt f b -> Alt f a # Applicative f => Applicative (Rec1 f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> Rec1 f a #(<*>) :: Rec1 f (a -> b) -> Rec1 f a -> Rec1 f b #liftA2 :: (a -> b -> c) -> Rec1 f a -> Rec1 f b -> Rec1 f c #(*>) :: Rec1 f a -> Rec1 f b -> Rec1 f b #(<*) :: Rec1 f a -> Rec1 f b -> Rec1 f a # (Applicative f, Monad f) => Applicative (WhenMissing f x) Equivalent to ReaderT k (ReaderT x (MaybeT f)).Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methodspure :: a -> WhenMissing f x a #(<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b #liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c #(*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b #(<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # (Functor m, Monad m) => Applicative (ErrorT e m) Instance detailsDefined in Control.Monad.Trans.Error Methodspure :: a -> ErrorT e m a #(<*>) :: ErrorT e m (a -> b) -> ErrorT e m a -> ErrorT e m b #liftA2 :: (a -> b -> c) -> ErrorT e m a -> ErrorT e m b -> ErrorT e m c #(*>) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m b #(<*) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m a # (Functor m, Monad m) => Applicative (ExceptT e m) Instance detailsDefined in Control.Monad.Trans.Except Methodspure :: a -> ExceptT e m a #(<*>) :: ExceptT e m (a -> b) -> ExceptT e m a -> ExceptT e m b #liftA2 :: (a -> b -> c) -> ExceptT e m a -> ExceptT e m b -> ExceptT e m c #(*>) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m b #(<*) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m a # Instance detailsDefined in Control.Monad.Trans.Identity Methodspure :: a -> IdentityT m a #(<*>) :: IdentityT m (a -> b) -> IdentityT m a -> IdentityT m b #liftA2 :: (a -> b -> c) -> IdentityT m a -> IdentityT m b -> IdentityT m c #(*>) :: IdentityT m a -> IdentityT m b -> IdentityT m b #(<*) :: IdentityT m a -> IdentityT m b -> IdentityT m a # Applicative m => Applicative (ReaderT r m) Instance detailsDefined in Control.Monad.Trans.Reader Methodspure :: a -> ReaderT r m a #(<*>) :: ReaderT r m (a -> b) -> ReaderT r m a -> ReaderT r m b #liftA2 :: (a -> b -> c) -> ReaderT r m a -> ReaderT r m b -> ReaderT r m c #(*>) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m b #(<*) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m a # (Functor m, Monad m) => Applicative (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Lazy Methodspure :: a -> StateT s m a #(<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b #liftA2 :: (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c #(*>) :: StateT s m a -> StateT s m b -> StateT s m b #(<*) :: StateT s m a -> StateT s m b -> StateT s m a # (Functor m, Monad m) => Applicative (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Strict Methodspure :: a -> StateT s m a #(<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b #liftA2 :: (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c #(*>) :: StateT s m a -> StateT s m b -> StateT s m b #(<*) :: StateT s m a -> StateT s m b -> StateT s m a # (Monoid w, Applicative m) => Applicative (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Lazy Methodspure :: a -> WriterT w m a #(<*>) :: WriterT w m (a -> b) -> WriterT w m a -> WriterT w m b #liftA2 :: (a -> b -> c) -> WriterT w m a -> WriterT w m b -> WriterT w m c #(*>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #(<*) :: WriterT w m a -> WriterT w m b -> WriterT w m a # (Monoid w, Applicative m) => Applicative (WriterT w m) Instance detailsDefined in Control.Monad.Trans.Writer.Strict Methodspure :: a -> WriterT w m a #(<*>) :: WriterT w m (a -> b) -> WriterT w m a -> WriterT w m b #liftA2 :: (a -> b -> c) -> WriterT w m a -> WriterT w m b -> WriterT w m c #(*>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #(<*) :: WriterT w m a -> WriterT w m b -> WriterT w m a # (Monoid a, Monoid b) => Applicative ((,,) a b) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methodspure :: a0 -> (a, b, a0) #(<*>) :: (a, b, a0 -> b0) -> (a, b, a0) -> (a, b, b0) #liftA2 :: (a0 -> b0 -> c) -> (a, b, a0) -> (a, b, b0) -> (a, b, c) #(*>) :: (a, b, a0) -> (a, b, b0) -> (a, b, b0) #(<*) :: (a, b, a0) -> (a, b, b0) -> (a, b, a0) # (Applicative f, Applicative g) => Applicative (Product f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Product Methodspure :: a -> Product f g a #(<*>) :: Product f g (a -> b) -> Product f g a -> Product f g b #liftA2 :: (a -> b -> c) -> Product f g a -> Product f g b -> Product f g c #(*>) :: Product f g a -> Product f g b -> Product f g b #(<*) :: Product f g a -> Product f g b -> Product f g a # (Applicative f, Applicative g) => Applicative (f :*: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> (f :*: g) a #(<*>) :: (f :*: g) (a -> b) -> (f :*: g) a -> (f :*: g) b #liftA2 :: (a -> b -> c) -> (f :*: g) a -> (f :*: g) b -> (f :*: g) c #(*>) :: (f :*: g) a -> (f :*: g) b -> (f :*: g) b #(<*) :: (f :*: g) a -> (f :*: g) b -> (f :*: g) a # Monoid c => Applicative (K1 i c :: Type -> Type) Since: base-4.12.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> K1 i c a #(<*>) :: K1 i c (a -> b) -> K1 i c a -> K1 i c b #liftA2 :: (a -> b -> c0) -> K1 i c a -> K1 i c b -> K1 i c c0 #(*>) :: K1 i c a -> K1 i c b -> K1 i c b #(<*) :: K1 i c a -> K1 i c b -> K1 i c a # (Monad f, Applicative f) => Applicative (WhenMatched f x y) Equivalent to ReaderT Key (ReaderT x (ReaderT y (MaybeT f)))Since: containers-0.5.9 Instance detailsDefined in Data.IntMap.Internal Methodspure :: a -> WhenMatched f x y a #(<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b #liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c #(*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b #(<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # (Applicative f, Monad f) => Applicative (WhenMissing f k x) Equivalent to  ReaderT k (ReaderT x (MaybeT f)) .Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methodspure :: a -> WhenMissing f k x a #(<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b #liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c #(*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b #(<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # Applicative (ContT r m) Instance detailsDefined in Control.Monad.Trans.Cont Methodspure :: a -> ContT r m a #(<*>) :: ContT r m (a -> b) -> ContT r m a -> ContT r m b #liftA2 :: (a -> b -> c) -> ContT r m a -> ContT r m b -> ContT r m c #(*>) :: ContT r m a -> ContT r m b -> ContT r m b #(<*) :: ContT r m a -> ContT r m b -> ContT r m a # (Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) Since: base-4.14.0.0 Instance detailsDefined in GHC.Base Methodspure :: a0 -> (a, b, c, a0) #(<*>) :: (a, b, c, a0 -> b0) -> (a, b, c, a0) -> (a, b, c, b0) #liftA2 :: (a0 -> b0 -> c0) -> (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, c0) #(*>) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, b0) #(<*) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, a0) # Applicative ((->) r) Since: base-2.1 Instance detailsDefined in GHC.Base Methodspure :: a -> r -> a #(<*>) :: (r -> (a -> b)) -> (r -> a) -> r -> b #liftA2 :: (a -> b -> c) -> (r -> a) -> (r -> b) -> r -> c #(*>) :: (r -> a) -> (r -> b) -> r -> b #(<*) :: (r -> a) -> (r -> b) -> r -> a # (Applicative f, Applicative g) => Applicative (Compose f g) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Compose Methodspure :: a -> Compose f g a #(<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b #liftA2 :: (a -> b -> c) -> Compose f g a -> Compose f g b -> Compose f g c #(*>) :: Compose f g a -> Compose f g b -> Compose f g b #(<*) :: Compose f g a -> Compose f g b -> Compose f g a # (Applicative f, Applicative g) => Applicative (f :.: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> (f :.: g) a #(<*>) :: (f :.: g) (a -> b) -> (f :.: g) a -> (f :.: g) b #liftA2 :: (a -> b -> c) -> (f :.: g) a -> (f :.: g) b -> (f :.: g) c #(*>) :: (f :.: g) a -> (f :.: g) b -> (f :.: g) b #(<*) :: (f :.: g) a -> (f :.: g) b -> (f :.: g) a # Applicative f => Applicative (M1 i c f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodspure :: a -> M1 i c f a #(<*>) :: M1 i c f (a -> b) -> M1 i c f a -> M1 i c f b #liftA2 :: (a -> b -> c0) -> M1 i c f a -> M1 i c f b -> M1 i c f c0 #(*>) :: M1 i c f a -> M1 i c f b -> M1 i c f b #(<*) :: M1 i c f a -> M1 i c f b -> M1 i c f a # (Monad f, Applicative f) => Applicative (WhenMatched f k x y) Equivalent to  ReaderT k (ReaderT x (ReaderT y (MaybeT f))) Since: containers-0.5.9 Instance detailsDefined in Data.Map.Internal Methodspure :: a -> WhenMatched f k x y a #(<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b #liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c #(*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b #(<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Lazy Methodspure :: a -> RWST r w s m a #(<*>) :: RWST r w s m (a -> b) -> RWST r w s m a -> RWST r w s m b #liftA2 :: (a -> b -> c) -> RWST r w s m a -> RWST r w s m b -> RWST r w s m c #(*>) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m b #(<*) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m a # (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) Instance detailsDefined in Control.Monad.Trans.RWS.Strict Methodspure :: a -> RWST r w s m a #(<*>) :: RWST r w s m (a -> b) -> RWST r w s m a -> RWST r w s m b #liftA2 :: (a -> b -> c) -> RWST r w s m a -> RWST r w s m b -> RWST r w s m c #(*>) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m b #(<*) :: RWST r w s m a -> RWST r w s m b -> RWST r w s m a # class Foldable (t :: TYPE LiftedRep -> Type) where # The Foldable class represents data structures that can be reduced to a summary value one element at a time. Strict left-associative folds are a good fit for space-efficient reduction, while lazy right-associative folds are a good fit for corecursive iteration, or for folds that short-circuit after processing an initial subsequence of the structure's elements. Instances can be derived automatically by enabling the DeriveFoldable extension. For example, a derived instance for a binary tree might be: {-# LANGUAGE DeriveFoldable #-} data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving Foldable A more detailed description can be found in the Overview section of Data.Foldable. For the class laws see the Laws section of Data.Foldable. Minimal complete definition Methods fold :: Monoid m => t m -> m # Given a structure with elements whose type is a Monoid, combine them via the monoid's (<>) operator. This fold is right-associative and lazy in the accumulator. When you need a strict left-associative fold, use foldMap' instead, with id as the map. #### Examples Expand Basic usage: >>> fold [[1, 2, 3], [4, 5], [6], []] [1,2,3,4,5,6]  >>> fold$ Node (Leaf (Sum 1)) (Sum 3) (Leaf (Sum 5))
Sum {getSum = 9}


Folds of unbounded structures do not terminate when the monoid's (<>) operator is strict:

>>> fold (repeat Nothing)
* Hangs forever *


Lazy corecursive folds of unbounded structures are fine:

>>> take 12 $fold$ map (\i -> [i..i+2]) [0..]
[0,1,2,1,2,3,2,3,4,3,4,5]
>>> sum $take 4000000$ fold $map (\i -> [i..i+2]) [0..] 2666668666666  foldMap :: Monoid m => (a -> m) -> t a -> m # Map each element of the structure into a monoid, and combine the results with (<>). This fold is right-associative and lazy in the accumulator. For strict left-associative folds consider foldMap' instead. #### Examples Expand Basic usage: >>> foldMap Sum [1, 3, 5] Sum {getSum = 9}  >>> foldMap Product [1, 3, 5] Product {getProduct = 15}  >>> foldMap (replicate 3) [1, 2, 3] [1,1,1,2,2,2,3,3,3]  When a Monoid's (<>) is lazy in its second argument, foldMap can return a result even from an unbounded structure. For example, lazy accumulation enables Data.ByteString.Builder to efficiently serialise large data structures and produce the output incrementally: >>> import qualified Data.ByteString.Lazy as L >>> import qualified Data.ByteString.Builder as B >>> let bld :: Int -> B.Builder; bld i = B.intDec i <> B.word8 0x20 >>> let lbs = B.toLazyByteString$ foldMap bld [0..]
>>> L.take 64 lbs
"0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24"


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

A left-associative variant of foldMap that is strict in the accumulator. Use this method for strict reduction when partial results are merged via (<>).

#### Examples

Expand

Define a Monoid over finite bit strings under xor. Use it to strictly compute the xor of a list of Int values.

>>> :set -XGeneralizedNewtypeDeriving
>>> import Data.Bits (Bits, FiniteBits, xor, zeroBits)
>>> import Data.Foldable (foldMap')
>>> import Numeric (showHex)
>>> 
>>> newtype X a = X a deriving (Eq, Bounded, Enum, Bits, FiniteBits)
>>> instance Bits a => Semigroup (X a) where X a <> X b = X (a xor b)
>>> instance Bits a => Monoid    (X a) where mempty     = X zeroBits
>>> 
>>> let bits :: [Int]; bits = [0xcafe, 0xfeed, 0xdeaf, 0xbeef, 0x5411]
>>> (\ (X a) -> showString "0x" . showHex a $"")$ foldMap' X bits
"0x42"


Since: base-4.13.0.0

foldr :: (a -> b -> b) -> b -> t a -> b #

Right-associative fold of a structure, lazy in the accumulator.

In the case of lists, foldr, when applied to a binary operator, a starting value (typically the right-identity of the operator), and a list, reduces the list using the binary operator, from right to left:

foldr f z [x1, x2, ..., xn] == x1 f (x2 f ... (xn f z)...)

Note that since the head of the resulting expression is produced by an application of the operator to the first element of the list, given an operator lazy in its right argument, foldr can produce a terminating expression from an unbounded list.

For a general Foldable structure this should be semantically identical to,

foldr f z = foldr f z . toList

#### Examples

Expand

Basic usage:

>>> foldr (||) False [False, True, False]
True

>>> foldr (||) False []
False

>>> foldr (\c acc -> acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
"foodcba"

##### Infinite structures

⚠️ Applying foldr to infinite structures usually doesn't terminate.

It may still terminate under one of the following conditions:

• the folding function is short-circuiting
• the folding function is lazy on its second argument
###### Short-circuiting

(||) short-circuits on True values, so the following terminates because there is a True value finitely far from the left side:

>>> foldr (||) False (True : repeat False)
True


But the following doesn't terminate:

>>> foldr (||) False (repeat False ++ [True])
* Hangs forever *

###### Laziness in the second argument

Applying foldr to infinite structures terminates when the operator is lazy in its second argument (the initial accumulator is never used in this case, and so could be left undefined, but [] is more clear):

>>> take 5 $foldr (\i acc -> i : fmap (+3) acc) [] (repeat 1) [1,4,7,10,13]  foldr' :: (a -> b -> b) -> b -> t a -> b # Right-associative fold of a structure, strict in the accumulator. This is rarely what you want. Since: base-4.6.0.0 foldl :: (b -> a -> b) -> b -> t a -> b # Left-associative fold of a structure, lazy in the accumulator. This is rarely what you want, but can work well for structures with efficient right-to-left sequencing and an operator that is lazy in its left argument. In the case of lists, foldl, when applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right: foldl f z [x1, x2, ..., xn] == (...((z f x1) f x2) f...) f xn Note that to produce the outermost application of the operator the entire input list must be traversed. Like all left-associative folds, foldl will diverge if given an infinite list. If you want an efficient strict left-fold, you probably want to use foldl' instead of foldl. The reason for this is that the latter does not force the inner results (e.g. z f x1 in the above example) before applying them to the operator (e.g. to (f x2)). This results in a thunk chain $$\mathcal{O}(n)$$ elements long, which then must be evaluated from the outside-in. For a general Foldable structure this should be semantically identical to: foldl f z = foldl f z . toList #### Examples Expand The first example is a strict fold, which in practice is best performed with foldl'. >>> foldl (+) 42 [1,2,3,4] 52  Though the result below is lazy, the input is reversed before prepending it to the initial accumulator, so corecursion begins only after traversing the entire input string. >>> foldl (\acc c -> c : acc) "abcd" "efgh" "hgfeabcd"  A left fold of a structure that is infinite on the right cannot terminate, even when for any finite input the fold just returns the initial accumulator: >>> foldl (\a _ -> a) 0$ repeat 1
* Hangs forever *


WARNING: When it comes to lists, you always want to use either foldl' or foldr instead.

foldl' :: (b -> a -> b) -> b -> t a -> b #

Left-associative fold of a structure but with strict application of the operator.

This ensures that each step of the fold is forced to Weak Head Normal Form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite structure to a single strict result (e.g. sum).

For a general Foldable structure this should be semantically identical to,

foldl' f z = foldl' f z . toList

Since: base-4.6.0.0

foldr1 :: (a -> a -> a) -> t a -> a #

A variant of foldr that has no base case, and thus may only be applied to non-empty structures.

This function is non-total and will raise a runtime exception if the structure happens to be empty.

#### Examples

Expand

Basic usage:

>>> foldr1 (+) [1..4]
10

>>> foldr1 (+) []
Exception: Prelude.foldr1: empty list

>>> foldr1 (+) Nothing
*** Exception: foldr1: empty structure

>>> foldr1 (-) [1..4]
-2

>>> foldr1 (&&) [True, False, True, True]
False

>>> foldr1 (||) [False, False, True, True]
True

>>> foldr1 (+) [1..]
* Hangs forever *


foldl1 :: (a -> a -> a) -> t a -> a #

A variant of foldl that has no base case, and thus may only be applied to non-empty structures.

This function is non-total and will raise a runtime exception if the structure happens to be empty.

foldl1 f = foldl1 f . toList

#### Examples

Expand

Basic usage:

>>> foldl1 (+) [1..4]
10

>>> foldl1 (+) []
*** Exception: Prelude.foldl1: empty list

>>> foldl1 (+) Nothing
*** Exception: foldl1: empty structure

>>> foldl1 (-) [1..4]
-8

>>> foldl1 (&&) [True, False, True, True]
False

>>> foldl1 (||) [False, False, True, True]
True

>>> foldl1 (+) [1..]
* Hangs forever *


null :: t a -> Bool #

Test whether the structure is empty. The default implementation is Left-associative and lazy in both the initial element and the accumulator. Thus optimised for structures where the first element can be accessed in constant time. Structures where this is not the case should have a non-default implementation.

#### Examples

Expand

Basic usage:

>>> null []
True

>>> null [1]
False


null is expected to terminate even for infinite structures. The default implementation terminates provided the structure is bounded on the left (there is a leftmost element).

>>> null [1..]
False


Since: base-4.8.0.0

length :: t a -> Int #

Returns the size/length of a finite structure as an Int. The default implementation just counts elements starting with the leftmost. Instances for structures that can compute the element count faster than via element-by-element counting, should provide a specialised implementation.

#### Examples

Expand

Basic usage:

>>> length []
0

>>> length ['a', 'b', 'c']
3
>>> length [1..]
* Hangs forever *


Since: base-4.8.0.0

elem :: Eq a => a -> t a -> Bool infix 4 #

Does the element occur in the structure?

Note: elem is often used in infix form.

#### Examples

Expand

Basic usage:

>>> 3 elem []
False

>>> 3 elem [1,2]
False

>>> 3 elem [1,2,3,4,5]
True


For infinite structures, the default implementation of elem terminates if the sought-after value exists at a finite distance from the left side of the structure:

>>> 3 elem [1..]
True

>>> 3 elem ([4..] ++ [3])
* Hangs forever *


Since: base-4.8.0.0

maximum :: Ord a => t a -> a #

The largest element of a non-empty structure.

This function is non-total and will raise a runtime exception if the structure happens to be empty. A structure that supports random access and maintains its elements in order should provide a specialised implementation to return the maximum in faster than linear time.

#### Examples

Expand

Basic usage:

>>> maximum [1..10]
10

>>> maximum []
*** Exception: Prelude.maximum: empty list

>>> maximum Nothing
*** Exception: maximum: empty structure


WARNING: This function is partial for possibly-empty structures like lists.

Since: base-4.8.0.0

minimum :: Ord a => t a -> a #

The least element of a non-empty structure.

This function is non-total and will raise a runtime exception if the structure happens to be empty. A structure that supports random access and maintains its elements in order should provide a specialised implementation to return the minimum in faster than linear time.

#### Examples

Expand

Basic usage:

>>> minimum [1..10]
1

>>> minimum []
*** Exception: Prelude.minimum: empty list

>>> minimum Nothing
*** Exception: minimum: empty structure


WARNING: This function is partial for possibly-empty structures like lists.

Since: base-4.8.0.0

sum :: Num a => t a -> a #

The sum function computes the sum of the numbers of a structure.

#### Examples

Expand

Basic usage:

>>> sum []
0

>>> sum [42]
42

>>> sum [1..10]
55

>>> sum [4.1, 2.0, 1.7]
7.8

>>> sum [1..]
* Hangs forever *


Since: base-4.8.0.0

product :: Num a => t a -> a #

The product function computes the product of the numbers of a structure.

#### Examples

Expand

Basic usage:

>>> product []
1

>>> product [42]
42

>>> product [1..10]
3628800

>>> product [4.1, 2.0, 1.7]
13.939999999999998

>>> product [1..]
* Hangs forever *


Since: base-4.8.0.0

#### Instances

Instances details

class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where #

Functors representing data structures that can be transformed to structures of the same shape by performing an Applicative (or, therefore, Monad) action on each element from left to right.

A more detailed description of what same shape means, the various methods, how traversals are constructed, and example advanced use-cases can be found in the Overview section of Data.Traversable.

For the class laws see the Laws section of Data.Traversable.

Minimal complete definition

Methods

traverse :: Applicative f => (a -> f b) -> t a -> f (t b) #

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see traverse_.

#### Examples

Expand

Basic usage:

In the first two examples we show each evaluated action mapping to the output structure.

>>> traverse Just [1,2,3,4]
Just [1,2,3,4]

>>> traverse id [Right 1, Right 2, Right 3, Right 4]
Right [1,2,3,4]


In the next examples, we show that Nothing and Left values short circuit the created structure.

>>> traverse (const Nothing) [1,2,3,4]
Nothing

>>> traverse (\x -> if odd x then Just x else Nothing)  [1,2,3,4]
Nothing

>>> traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]
Left 0


sequenceA :: Applicative f => t (f a) -> f (t a) #

Evaluate each action in the structure from left to right, and collect the results. For a version that ignores the results see sequenceA_.

#### Examples

Expand

Basic usage:

For the first two examples we show sequenceA fully evaluating a a structure and collecting the results.

>>> sequenceA [Just 1, Just 2, Just 3]
Just [1,2,3]

>>> sequenceA [Right 1, Right 2, Right 3]
Right [1,2,3]


The next two example show Nothing and Just will short circuit the resulting structure if present in the input. For more context, check the Traversable instances for Either and Maybe.

>>> sequenceA [Just 1, Just 2, Just 3, Nothing]
Nothing

>>> sequenceA [Right 1, Right 2, Right 3, Left 4]
Left 4


mapM :: Monad m => (a -> m b) -> t a -> m (t b) #

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see mapM_.

#### Examples

Expand

mapM is literally a traverse with a type signature restricted to Monad. Its implementation may be more efficient due to additional power of Monad.

sequence :: Monad m => t (m a) -> m (t a) #

Evaluate each monadic action in the structure from left to right, and collect the results. For a version that ignores the results see sequence_.

#### Examples

Expand

Basic usage:

The first two examples are instances where the input and and output of sequence are isomorphic.

>>> sequence $Right [1,2,3,4] [Right 1,Right 2,Right 3,Right 4]  >>> sequence$ [Right 1,Right 2,Right 3,Right 4]
Right [1,2,3,4]


The following examples demonstrate short circuit behavior for sequence.

>>> sequence $Left [1,2,3,4] Left [1,2,3,4]  >>> sequence$ [Left 0, Right 1,Right 2,Right 3,Right 4]
Left 0


#### Instances

Instances details