| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Papa.Base.Export.Control.Applicative
- class Functor f => Applicative f where
- class Applicative f => Alternative f where
- data Const k a b :: forall k. * -> k -> *
- data WrappedMonad m a :: (* -> *) -> * -> *
- data WrappedArrow a b c :: (* -> * -> *) -> * -> * -> *
- data ZipList a :: * -> *
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<$) :: Functor f => forall a b. a -> f b -> f a
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- optional :: Alternative f => f a -> f (Maybe a)
Documentation
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
pureid<*>v = v- composition
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)- homomorphism
puref<*>purex =pure(f x)- interchange
u
<*>purey =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).
Methods
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.
Instances
| Applicative [] | |
| Applicative Maybe | |
| Applicative IO | |
| Applicative U1 | |
| Applicative Par1 | |
| Applicative Id | |
| Applicative Min | |
| Applicative Max | |
| Applicative First | |
| Applicative Last | |
| Applicative Option | |
| Applicative NonEmpty | |
| Applicative ZipList | |
| Applicative Dual | |
| Applicative Sum | |
| Applicative Product | |
| Applicative First | |
| Applicative Last | |
| Applicative ((->) a) | |
| Applicative (Either e) | |
| Applicative f => Applicative (Rec1 f) | |
| Monoid a => Applicative ((,) a) | |
| Applicative (StateL s) | |
| Applicative (StateR s) | |
| Monad m => Applicative (WrappedMonad m) | |
| Applicative (Proxy *) | |
| (Applicative f, Applicative g) => Applicative ((:*:) f g) | |
| (Applicative f, Applicative g) => Applicative ((:.:) f g) | |
| Arrow a => Applicative (WrappedArrow a b) | |
| Monoid m => Applicative (Const * m) | |
| Applicative f => Applicative (Alt * f) | |
| Applicative f => Applicative (M1 i c f) | |
class Applicative f => Alternative f where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
| Alternative [] | |
| Alternative Maybe | |
| Alternative IO | |
| Alternative U1 | |
| Alternative Option | |
| Alternative f => Alternative (Rec1 f) | |
| MonadPlus m => Alternative (WrappedMonad m) | |
| Alternative (Proxy *) | |
| (Alternative f, Alternative g) => Alternative ((:*:) f g) | |
| (Alternative f, Applicative g) => Alternative ((:.:) f g) | |
| (ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | |
| Alternative f => Alternative (Alt * f) | |
| Alternative f => Alternative (M1 i c f) | |
data Const k a b :: forall k. * -> k -> * #
The Const functor.
Instances
| Functor (Const * m) | |
| Monoid m => Applicative (Const * m) | |
| Foldable (Const * m) | |
| Traversable (Const * m) | |
| Generic1 (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) | |
data WrappedMonad m a :: (* -> *) -> * -> * #
Instances
| Monad m => Monad (WrappedMonad m) | |
| Monad m => Functor (WrappedMonad m) | |
| Monad m => Applicative (WrappedMonad m) | |
| Generic1 (WrappedMonad m) | |
| MonadPlus m => Alternative (WrappedMonad m) | |
| Generic (WrappedMonad m a) | |
| type Rep1 (WrappedMonad m) | |
| type Rep (WrappedMonad m a) | |
data WrappedArrow a b c :: (* -> * -> *) -> * -> * -> * #
Instances
| 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) | |
(<$>) :: 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 to a Maybe Int using Maybe Stringshow:
>>>show <$> NothingNothing>>>show <$> Just 3Just "3"
Convert from an to an Either Int IntEither IntString using show:
>>>show <$> Left 17Left 17>>>show <$> Right 17Right "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)
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*> with the arguments reversed.
liftA :: Applicative f => (a -> b) -> f a -> f b #
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
optional :: Alternative f => f a -> f (Maybe a) #
One or none.