Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- class Functor f => Applicative f where
- pure :: Applicative f => forall a. a -> f a
- (<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b
- (*>) :: Applicative f => forall a b. f a -> f b -> f b
- (<*) :: Applicative f => forall a b. f a -> f b -> f a
- newtype Const k a b :: forall k. * -> k -> * = Const {
- getConst :: a
- newtype WrappedArrow a b c :: (* -> * -> *) -> * -> * -> * = WrapArrow {
- unwrapArrow :: a b c
- newtype ZipList a :: * -> * = ZipList {
- getZipList :: [a]
- liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- forever :: Applicative f => f a -> f b
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- replicateA :: Applicative f => Int -> f a -> f [a]
- replicateA_ :: Applicative f => Int -> f a -> f ()
- filterA :: Applicative f => (a -> f Bool) -> [a] -> f [a]
Applicative functors
class Functor f => Applicative f where #
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
- 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:
As a consequence of these laws, the Functor
instance for f
will satisfy
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
(*>) :: 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.
pure :: Applicative f => forall a. a -> f a #
Lift a value.
(<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b #
Sequential application.
(*>) :: Applicative f => forall a b. f a -> f b -> f b #
Sequence actions, discarding the value of the first argument.
(<*) :: Applicative f => forall a b. f a -> f b -> f a #
Sequence actions, discarding the value of the second argument.
Instances
newtype Const k a b :: forall k. * -> k -> * #
The Const
functor.
Eq2 (Const *) | |
Ord2 (Const *) | |
Read2 (Const *) | |
Show2 (Const *) | |
Bifunctor (Const *) | |
Functor (Const * m) | |
Monoid m => Applicative (Const * m) | |
Foldable (Const * m) | |
Traversable (Const * m) | |
Generic1 (Const * a) | |
Eq a => Eq1 (Const * a) | |
Ord a => Ord1 (Const * a) | |
Read a => Read1 (Const * a) | |
Show a => Show1 (Const * a) | |
Bounded a => Bounded (Const k a b) | |
Enum a => Enum (Const k a b) | |
Eq a => Eq (Const k a b) | |
Floating a => Floating (Const k a b) | |
Fractional a => Fractional (Const k a b) | |
Integral a => Integral (Const k a b) | |
Num a => Num (Const k a b) | |
Ord a => Ord (Const k a b) | |
Read a => Read (Const k a b) | This instance would be equivalent to the derived instances of the
|
Real a => Real (Const k a b) | |
RealFloat a => RealFloat (Const k a b) | |
RealFrac a => RealFrac (Const k a b) | |
Show a => Show (Const k a b) | This instance would be equivalent to the derived instances of the
|
Ix a => Ix (Const k a b) | |
IsString a => IsString (Const * a b) | |
Generic (Const k a b) | |
Semigroup a => Semigroup (Const k a b) | |
Monoid a => Monoid (Const k a b) | |
Storable a => Storable (Const k a b) | |
Bits a => Bits (Const k a b) | |
FiniteBits a => FiniteBits (Const k a b) | |
type Rep1 (Const * a) | |
type Rep (Const k a b) | |
newtype WrappedArrow a b c :: (* -> * -> *) -> * -> * -> * #
WrapArrow | |
|
Arrow a => Functor (WrappedArrow a b) | |
Arrow a => Applicative (WrappedArrow a b) | |
Generic1 (WrappedArrow a b) | |
(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | |
Generic (WrappedArrow a b c) | |
type Rep1 (WrappedArrow a b) | |
type Rep (WrappedArrow a b c) | |
Lists, but with an Applicative
functor based on zipping, so that
f<$>
ZipList
xs1<*>
...<*>
ZipList
xsn =ZipList
(zipWithn f xs1 ... xsn)
ZipList | |
|
Utility functions
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
forever :: Applicative f => f a -> f b #
repeats the action infinitely.forever
act
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
replicateA :: Applicative f => Int -> f a -> f [a] Source #
performs the action replicateA
n actn
times,
gathering the results.
replicateA_ :: Applicative f => Int -> f a -> f () Source #
Like replicateA
, but discards the result.