ghc-8.2.1: The GHC API

Description

Utilities related to Monad and Applicative classes Mostly for backwards compatibility.

Synopsis

# Documentation

class Functor f => Applicative (f :: * -> *) 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 • (<*>) = ap (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. (*>) :: f a -> f b -> f b infixl 4 # Sequence actions, discarding the value of the first argument. (<*) :: f a -> f b -> f a infixl 4 # Sequence actions, discarding the value of the second argument. Instances Since: 2.1 Methods pure :: a -> [a] # (<*>) :: [a -> b] -> [a] -> [b] # liftA2 :: (a -> b -> c) -> [a] -> [b] -> [c] # (*>) :: [a] -> [b] -> [b] # (<*) :: [a] -> [b] -> [a] # Since: 2.1 Methods pure :: 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: 2.1 Methods pure :: 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 # Since: 4.9.0.0 Methods pure :: 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 # Methods pure :: 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 # Since: 4.5.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: 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: 4.9.0.0 Methods pure :: a -> Option a # (<*>) :: Option (a -> b) -> Option a -> Option b # liftA2 :: (a -> b -> c) -> Option a -> Option b -> Option c # (*>) :: Option a -> Option b -> Option b # (<*) :: Option a -> Option b -> Option a # Since: 4.9.0.0 Methods pure :: 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 # 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: 2.1 Methods pure :: 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: 4.8.0.0 Methods pure :: 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: 4.8.0.0 Methods pure :: 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: 4.8.0.0 Methods pure :: 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: 4.8.0.0 Methods pure :: 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: 4.8.0.0 Methods pure :: 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 # Methods pure :: 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 # Methods pure :: 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: 4.6.0.0 Methods pure :: 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: 4.6.0.0 Methods pure :: 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 # Methods pure :: a -> PutM a # (<*>) :: PutM (a -> b) -> PutM a -> PutM b # liftA2 :: (a -> b -> c) -> PutM a -> PutM b -> PutM c # (*>) :: PutM a -> PutM b -> PutM b # (<*) :: PutM a -> PutM b -> PutM a # Methods pure :: a -> Get a # (<*>) :: Get (a -> b) -> Get a -> Get b # liftA2 :: (a -> b -> c) -> Get a -> Get b -> Get c # (*>) :: Get a -> Get b -> Get b # (<*) :: Get a -> Get b -> Get a # Applicative Put Methods pure :: a -> Put a # (<*>) :: Put (a -> b) -> Put a -> Put b # liftA2 :: (a -> b -> c) -> Put a -> Put b -> Put c # (*>) :: Put a -> Put b -> Put b # (<*) :: Put a -> Put b -> Put a # Methods pure :: 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 # Methods pure :: 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 # Methods pure :: a -> VM a # (<*>) :: VM (a -> b) -> VM a -> VM b # liftA2 :: (a -> b -> c) -> VM a -> VM b -> VM c # (*>) :: VM a -> VM b -> VM b # (<*) :: VM a -> VM b -> VM a # Methods pure :: a -> Capability a # (<*>) :: Capability (a -> b) -> Capability a -> Capability b # liftA2 :: (a -> b -> c) -> Capability a -> Capability b -> Capability c # (*>) :: Capability a -> Capability b -> Capability b # (<*) :: Capability a -> Capability b -> Capability a # # Methods pure :: a -> Pair a # (<*>) :: Pair (a -> b) -> Pair a -> Pair b # liftA2 :: (a -> b -> c) -> Pair a -> Pair b -> Pair c # (*>) :: Pair a -> Pair b -> Pair b # (<*) :: Pair a -> Pair b -> Pair a # # Methods pure :: a -> UniqSM a # (<*>) :: UniqSM (a -> b) -> UniqSM a -> UniqSM b # liftA2 :: (a -> b -> c) -> UniqSM a -> UniqSM b -> UniqSM c # (*>) :: UniqSM a -> UniqSM b -> UniqSM b # (<*) :: UniqSM a -> UniqSM b -> UniqSM a # # Methods pure :: 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 # # Methods pure :: a -> PD a # (<*>) :: PD (a -> b) -> PD a -> PD b # liftA2 :: (a -> b -> c) -> PD a -> PD b -> PD c # (*>) :: PD a -> PD b -> PD b # (<*) :: PD a -> PD b -> PD a # # # Methods pure :: a -> LlvmM a # (<*>) :: LlvmM (a -> b) -> LlvmM a -> LlvmM b # liftA2 :: (a -> b -> c) -> LlvmM a -> LlvmM b -> LlvmM c # (*>) :: LlvmM a -> LlvmM b -> LlvmM b # (<*) :: LlvmM a -> LlvmM b -> LlvmM a # # Methods pure :: a -> FCode a # (<*>) :: FCode (a -> b) -> FCode a -> FCode b # liftA2 :: (a -> b -> c) -> FCode a -> FCode b -> FCode c # (*>) :: FCode a -> FCode b -> FCode b # (<*) :: FCode a -> FCode b -> FCode a # # Methods pure :: a -> CmmParse a # (<*>) :: CmmParse (a -> b) -> CmmParse a -> CmmParse b # liftA2 :: (a -> b -> c) -> CmmParse a -> CmmParse b -> CmmParse c # (*>) :: CmmParse a -> CmmParse b -> CmmParse b # (<*) :: CmmParse a -> CmmParse b -> CmmParse a # # Methods pure :: a -> Hsc a # (<*>) :: Hsc (a -> b) -> Hsc a -> Hsc b # liftA2 :: (a -> b -> c) -> Hsc a -> Hsc b -> Hsc c # (*>) :: Hsc a -> Hsc b -> Hsc b # (<*) :: Hsc a -> Hsc b -> Hsc a # # Methods pure :: a -> TcPluginM a # (<*>) :: TcPluginM (a -> b) -> TcPluginM a -> TcPluginM b # liftA2 :: (a -> b -> c) -> TcPluginM a -> TcPluginM b -> TcPluginM c # (*>) :: TcPluginM a -> TcPluginM b -> TcPluginM b # (<*) :: TcPluginM a -> TcPluginM b -> TcPluginM a # # # Methods pure :: a -> Ghc a # (<*>) :: Ghc (a -> b) -> Ghc a -> Ghc b # liftA2 :: (a -> b -> c) -> Ghc a -> Ghc b -> Ghc c # (*>) :: Ghc a -> Ghc b -> Ghc b # (<*) :: Ghc a -> Ghc b -> Ghc a # # Methods pure :: a -> CoreM a # (<*>) :: CoreM (a -> b) -> CoreM a -> CoreM b # liftA2 :: (a -> b -> c) -> CoreM a -> CoreM b -> CoreM c # (*>) :: CoreM a -> CoreM b -> CoreM b # (<*) :: CoreM a -> CoreM b -> CoreM a # # Methods pure :: a -> SimplM a # (<*>) :: SimplM (a -> b) -> SimplM a -> SimplM b # liftA2 :: (a -> b -> c) -> SimplM a -> SimplM b -> SimplM c # (*>) :: SimplM a -> SimplM b -> SimplM b # (<*) :: SimplM a -> SimplM b -> SimplM a # # Methods pure :: a -> CpsRn a # (<*>) :: CpsRn (a -> b) -> CpsRn a -> CpsRn b # liftA2 :: (a -> b -> c) -> CpsRn a -> CpsRn b -> CpsRn c # (*>) :: CpsRn a -> CpsRn b -> CpsRn b # (<*) :: CpsRn a -> CpsRn b -> CpsRn a # # Methods pure :: a -> OccCheckResult a # (<*>) :: OccCheckResult (a -> b) -> OccCheckResult a -> OccCheckResult b # liftA2 :: (a -> b -> c) -> OccCheckResult a -> OccCheckResult b -> OccCheckResult c # # Methods pure :: a -> TcS a # (<*>) :: TcS (a -> b) -> TcS a -> TcS b # liftA2 :: (a -> b -> c) -> TcS a -> TcS b -> TcS c # (*>) :: TcS a -> TcS b -> TcS b # (<*) :: TcS a -> TcS b -> TcS a # # Methods pure :: a -> VM a # (<*>) :: VM (a -> b) -> VM a -> VM b # liftA2 :: (a -> b -> c) -> VM a -> VM b -> VM c # (*>) :: VM a -> VM b -> VM b # (<*) :: VM a -> VM b -> VM a # # Methods pure :: a -> NatM a # (<*>) :: NatM (a -> b) -> NatM a -> NatM b # liftA2 :: (a -> b -> c) -> NatM a -> NatM b -> NatM c # (*>) :: NatM a -> NatM b -> NatM b # (<*) :: NatM a -> NatM b -> NatM a # Since: 3.0 Methods pure :: 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 # Since: 4.9.0.0 Methods pure :: 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 # 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: 2.1 Methods pure :: a -> (a, a) # (<*>) :: (a, a -> b) -> (a, a) -> (a, b) # liftA2 :: (a -> b -> c) -> (a, a) -> (a, b) -> (a, c) # (*>) :: (a, a) -> (a, b) -> (a, b) # (<*) :: (a, a) -> (a, b) -> (a, a) # Since: 4.4.0.0 Methods pure :: a -> ST s a # (<*>) :: ST s (a -> b) -> ST s a -> ST s b # liftA2 :: (a -> b -> c) -> ST s a -> ST s b -> ST s c # (*>) :: ST s a -> ST s b -> ST s b # (<*) :: ST s a -> ST s b -> ST s a # Monad m => Applicative (WrappedMonad m) Since: 2.1 Methods pure :: 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: 4.6.0.0 Methods pure :: a -> ArrowMonad a a # (<*>) :: ArrowMonad a (a -> b) -> ArrowMonad a a -> ArrowMonad a b # liftA2 :: (a -> b -> c) -> ArrowMonad a a -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a -> ArrowMonad a b -> ArrowMonad a a # Since: 4.7.0.0 Methods pure :: 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 (SetM s) Methods pure :: a -> SetM s a # (<*>) :: SetM s (a -> b) -> SetM s a -> SetM s b # liftA2 :: (a -> b -> c) -> SetM s a -> SetM s b -> SetM s c # (*>) :: SetM s a -> SetM s b -> SetM s b # (<*) :: SetM s a -> SetM s b -> SetM s a # Applicative (State s) Methods pure :: a -> State s a # (<*>) :: State s (a -> b) -> State s a -> State s b # liftA2 :: (a -> b -> c) -> State s a -> State s b -> State s c # (*>) :: State s a -> State s b -> State s b # (<*) :: State s a -> State s b -> State s a # Monad m => Applicative (UniqueMonadT m) Methods pure :: a -> UniqueMonadT m a # (<*>) :: UniqueMonadT m (a -> b) -> UniqueMonadT m a -> UniqueMonadT m b # liftA2 :: (a -> b -> c) -> UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m c # (*>) :: UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m b # (<*) :: UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m a # (Functor m, Monad m) => Applicative (MaybeT m) Methods pure :: a -> MaybeT m a # (<*>) :: MaybeT m (a -> b) -> MaybeT m a -> MaybeT m b # liftA2 :: (a -> b -> c) -> MaybeT m a -> MaybeT m b -> MaybeT m c # (*>) :: MaybeT m a -> MaybeT m b -> MaybeT m b # (<*) :: MaybeT m a -> MaybeT m b -> MaybeT m a # # Methods pure :: a -> ListT f a # (<*>) :: ListT f (a -> b) -> ListT f a -> ListT f b # liftA2 :: (a -> b -> c) -> ListT f a -> ListT f b -> ListT f c # (*>) :: ListT f a -> ListT f b -> ListT f b # (<*) :: ListT f a -> ListT f b -> ListT f a # # Methods pure :: a -> State s a # (<*>) :: State s (a -> b) -> State s a -> State s b # liftA2 :: (a -> b -> c) -> State s a -> State s b -> State s c # (*>) :: State s a -> State s b -> State s b # (<*) :: State s a -> State s b -> State s a # Applicative (MaybeErr err) # Methods pure :: a -> MaybeErr err a # (<*>) :: MaybeErr err (a -> b) -> MaybeErr err a -> MaybeErr err b # liftA2 :: (a -> b -> c) -> MaybeErr err a -> MaybeErr err b -> MaybeErr err c # (*>) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err b # (<*) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err a # # Methods pure :: a -> CmdLineP s a # (<*>) :: CmdLineP s (a -> b) -> CmdLineP s a -> CmdLineP s b # liftA2 :: (a -> b -> c) -> CmdLineP s a -> CmdLineP s b -> CmdLineP s c # (*>) :: CmdLineP s a -> CmdLineP s b -> CmdLineP s b # (<*) :: CmdLineP s a -> CmdLineP s b -> CmdLineP s a # Monad m => Applicative (EwM m) # Methods pure :: a -> EwM m a # (<*>) :: EwM m (a -> b) -> EwM m a -> EwM m b # liftA2 :: (a -> b -> c) -> EwM m a -> EwM m b -> EwM m c # (*>) :: EwM m a -> EwM m b -> EwM m b # (<*) :: EwM m a -> EwM m b -> EwM m a # # Methods pure :: a -> IOEnv m a # (<*>) :: IOEnv m (a -> b) -> IOEnv m a -> IOEnv m b # liftA2 :: (a -> b -> c) -> IOEnv m a -> IOEnv m b -> IOEnv m c # (*>) :: IOEnv m a -> IOEnv m b -> IOEnv m b # (<*) :: IOEnv m a -> IOEnv m b -> IOEnv m a # Applicative (RegM freeRegs) # Methods pure :: a -> RegM freeRegs a # (<*>) :: RegM freeRegs (a -> b) -> RegM freeRegs a -> RegM freeRegs b # liftA2 :: (a -> b -> c) -> RegM freeRegs a -> RegM freeRegs b -> RegM freeRegs c # (*>) :: RegM freeRegs a -> RegM freeRegs b -> RegM freeRegs b # (<*) :: RegM freeRegs a -> RegM freeRegs b -> RegM freeRegs a # Applicative m => Applicative (GhcT m) # Methods pure :: a -> GhcT m a # (<*>) :: GhcT m (a -> b) -> GhcT m a -> GhcT m b # liftA2 :: (a -> b -> c) -> GhcT m a -> GhcT m b -> GhcT m c # (*>) :: GhcT m a -> GhcT m b -> GhcT m b # (<*) :: GhcT m a -> GhcT m b -> GhcT m a # Applicative f => Applicative (Rec1 * f) Since: 4.9.0.0 Methods pure :: 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 # Arrow a => Applicative (WrappedArrow a b) Since: 2.1 Methods pure :: a -> WrappedArrow a b a # (<*>) :: WrappedArrow a b (a -> b) -> WrappedArrow a b a -> WrappedArrow a b b # liftA2 :: (a -> b -> c) -> WrappedArrow a b a -> WrappedArrow a b b -> WrappedArrow a b c # (*>) :: WrappedArrow a b a -> WrappedArrow a b b -> WrappedArrow a b b # (<*) :: WrappedArrow a b a -> WrappedArrow a b b -> WrappedArrow a b a # Monoid m => Applicative (Const * m) Since: 2.0.1 Methods pure :: 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 (Alt * f) Methods pure :: 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, Monad f) => Applicative (WhenMissing f x) Equivalent to ReaderT k (ReaderT x (MaybeT f)). Methods pure :: 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 # (Monoid w, Applicative m) => Applicative (WriterT w m) Methods pure :: 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 # (Functor m, Monad m) => Applicative (StateT s m) Methods pure :: 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) Methods pure :: 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 (ExceptT e m) Methods pure :: 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 # Monad m => Applicative (Stream m a) # Methods pure :: a -> Stream m a a # (<*>) :: Stream m a (a -> b) -> Stream m a a -> Stream m a b # liftA2 :: (a -> b -> c) -> Stream m a a -> Stream m a b -> Stream m a c # (*>) :: Stream m a a -> Stream m a b -> Stream m a b # (<*) :: Stream m a a -> Stream m a b -> Stream m a a # Since: 2.1 Methods pure :: a -> (LiftedRep -> LiftedRep) a a # (<*>) :: (LiftedRep -> LiftedRep) a (a -> b) -> (LiftedRep -> LiftedRep) a a -> (LiftedRep -> LiftedRep) a b # liftA2 :: (a -> b -> c) -> (LiftedRep -> LiftedRep) a a -> (LiftedRep -> LiftedRep) a b -> (LiftedRep -> LiftedRep) a c # (*>) :: (LiftedRep -> LiftedRep) a a -> (LiftedRep -> LiftedRep) a b -> (LiftedRep -> LiftedRep) a b # (<*) :: (LiftedRep -> LiftedRep) a a -> (LiftedRep -> LiftedRep) a b -> (LiftedRep -> LiftedRep) a a # (Applicative f, Applicative g) => Applicative ((:*:) * f g) Since: 4.9.0.0 Methods pure :: 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 # (Monad f, Applicative f) => Applicative (WhenMatched f x y) Equivalent to ReaderT Key (ReaderT x (ReaderT y (MaybeT f))) Methods pure :: 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)) . Methods pure :: 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 m => Applicative (ReaderT * r m) Methods pure :: 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 # Applicative f => Applicative (M1 * i c f) Since: 4.9.0.0 Methods pure :: 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 -> c) -> M1 * i c f a -> M1 * i c f b -> M1 * i c f c # (*>) :: 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 # (Applicative f, Applicative g) => Applicative ((:.:) * * f g) Since: 4.9.0.0 Methods pure :: 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 # (Monad f, Applicative f) => Applicative (WhenMatched f k x y) Equivalent to  ReaderT k (ReaderT x (ReaderT y (MaybeT f)))  Methods pure :: 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 # (<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #

An infix synonym for fmap.

The name of this operator is an allusion to $. Note the similarities between their types:  ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b Whereas $ is function application, <$> is function application lifted over a Functor. #### Examples Convert from a Maybe Int to a Maybe String using show: >>> show <$> Nothing
Nothing
>>> show <$> Just 3 Just "3"  Convert from an Either Int Int to an Either Int String using show: >>> show <$> Left 17
Left 17
>>> show <$> Right 17 Right "17"  Double each element of a list: >>> (*2) <$> [1,2,3]
[2,4,6]


Apply even to the second element of a pair:

>>> even <\$> (2,2)
(2,True)


class Monad m => MonadFix (m :: * -> *) where #

Monads having fixed points with a 'knot-tying' semantics. Instances of MonadFix should satisfy the following laws:

purity
mfix (return . h) = return (fix h)
left shrinking (or tightening)
mfix (\x -> a >>= \y -> f x y) = a >>= \y -> mfix (\x -> f x y)
sliding
mfix (liftM h . f) = liftM h (mfix (f . h)), for strict h.
nesting
mfix (\x -> mfix (\y -> f x y)) = mfix (\x -> f x x)

This class is used in the translation of the recursive do notation supported by GHC and Hugs.

Minimal complete definition

mfix

Methods

mfix :: (a -> m a) -> m a #

The fixed point of a monadic computation. mfix f executes the action f only once, with the eventual output fed back as the input. Hence f should not be strict, for then mfix f would diverge.

Instances

class Monad m => MonadIO (m :: * -> *) where #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

• liftIO . return = return
• liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

 Since: 4.9.0.0 MethodsliftIO :: IO a -> IO a # # MethodsliftIO :: IO a -> Hsc a # # MethodsliftIO :: IO a -> CompPipeline a # # MethodsliftIO :: IO a -> Ghc a # # MethodsliftIO :: IO a -> CoreM a # # MethodsliftIO :: IO a -> SimplM a # # MethodsliftIO :: IO a -> VM a # MonadIO m => MonadIO (MaybeT m) MethodsliftIO :: IO a -> MaybeT m a # MonadIO (IOEnv env) # MethodsliftIO :: IO a -> IOEnv env a # MonadIO m => MonadIO (GhcT m) # MethodsliftIO :: IO a -> GhcT m a # (Monoid w, MonadIO m) => MonadIO (WriterT w m) MethodsliftIO :: IO a -> WriterT w m a # MonadIO m => MonadIO (StateT s m) MethodsliftIO :: IO a -> StateT s m a # MonadIO m => MonadIO (StateT s m) MethodsliftIO :: IO a -> StateT s m a # MonadIO m => MonadIO (ExceptT e m) MethodsliftIO :: IO a -> ExceptT e m a # MonadIO m => MonadIO (ReaderT * r m) MethodsliftIO :: IO a -> ReaderT * r m a #

liftIO1 :: MonadIO m => (a -> IO b) -> a -> m b Source #

Lift an IO operation with 1 argument into another monad

liftIO2 :: MonadIO m => (a -> b -> IO c) -> a -> b -> m c Source #

Lift an IO operation with 2 arguments into another monad

liftIO3 :: MonadIO m => (a -> b -> c -> IO d) -> a -> b -> c -> m d Source #

Lift an IO operation with 3 arguments into another monad

liftIO4 :: MonadIO m => (a -> b -> c -> d -> IO e) -> a -> b -> c -> d -> m e Source #

Lift an IO operation with 4 arguments into another monad

zipWith3M :: Monad m => (a -> b -> c -> m d) -> [a] -> [b] -> [c] -> m [d] Source #

zipWith3M_ :: Monad m => (a -> b -> c -> m d) -> [a] -> [b] -> [c] -> m () Source #

zipWith4M :: Monad m => (a -> b -> c -> d -> m e) -> [a] -> [b] -> [c] -> [d] -> m [e] Source #

zipWithAndUnzipM :: Monad m => (a -> b -> m (c, d)) -> [a] -> [b] -> m ([c], [d]) Source #

mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #

The mapAndUnzipM function maps its first argument over a list, returning the result as a pair of lists. This function is mainly used with complicated data structures or a state-transforming monad.

mapAndUnzip3M :: Monad m => (a -> m (b, c, d)) -> [a] -> m ([b], [c], [d]) Source #

mapAndUnzipM for triples

mapAndUnzip4M :: Monad m => (a -> m (b, c, d, e)) -> [a] -> m ([b], [c], [d], [e]) Source #

mapAndUnzip5M :: Monad m => (a -> m (b, c, d, e, f)) -> [a] -> m ([b], [c], [d], [e], [f]) Source #

Arguments

 :: Monad m => (acc -> x -> m (acc, y)) combining function -> acc initial state -> [x] inputs -> m (acc, [y]) final state, outputs

mapSndM :: Monad m => (b -> m c) -> [(a, b)] -> m [(a, c)] Source #

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

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

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

fmapEitherM :: Monad m => (a -> m b) -> (c -> m d) -> Either a c -> m (Either b d) Source #

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

Monadic version of any, aborts the computation at the first True value

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

Monad version of all, aborts the computation at the first False value

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

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

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

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

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

Monadic version of fmap specialised for Maybe

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

Monadic version of when, taking the condition in the monad

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

Monadic version of unless, taking the condition in the monad