| Copyright | Conor McBride and Ross Paterson 2005 |
|---|---|
| License | BSD-style (see the LICENSE file in the distribution) |
| Maintainer | libraries@haskell.org |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Control.Applicative
Description
This module describes a structure intermediate between a functor and a monad (technically, a strong lax monoidal functor). Compared with monads, this interface lacks the full power of the binding operation>>=, but
Traversable class.This interface was introduced for parsers by Niklas Röjemo, because it admits more sharing than the monadic interface. The names here are mostly based on parsing work by Doaitse Swierstra.
For more details, seeApplicative Programming with Effects, by Conor McBride and Ross Paterson.
Synopsis
classFunctor f =>Applicative fwhereSource#
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
pureid<*>v = v
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)
puref<*>purex =pure(f x)
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, theFunctor instance forf will satisfy
Iff is also aMonad, it should satisfy
(which implies thatpure and<*> satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f binfixl 4Source#
Sequential application.
(*>) :: f a -> f b -> f binfixl 4Source#
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f ainfixl 4Source#
Sequence actions, discarding the value of the second argument.
Instances
classApplicative f =>Alternative fwhereSource#
A monoid on applicative functors.
If defined,some andmany should be the least solutions of the equations:
Methods
The identity of<|>
(<|>) :: f a -> f a -> f ainfixl 3Source#
An associative binary operation
One or more.
Zero or more.
Instances
TheConst functor.
Instances
newtypeWrappedMonad m aSource#
Constructors
| WrapMonad | |
Fields
| |
Instances
newtypeWrappedArrow a b cSource#
Constructors
| WrapArrow | |
Fields
| |
Instances
Lists, but with anApplicative functor based on zipping, so that
f<$>ZipListxs1<*>...<*>ZipListxsn =ZipList(zipWithn f xs1 ... xsn)
Constructors
| ZipList | |
Fields
| |
Instances
| FunctorZipListSource# | |
| ApplicativeZipListSource# | |
| FoldableZipListSource# | |
Methods fold ::Monoid m =>ZipList m -> mSource# foldMap ::Monoid m => (a -> m) ->ZipList a -> mSource# foldr :: (a -> b -> b) -> b ->ZipList a -> bSource# foldr' :: (a -> b -> b) -> b ->ZipList a -> bSource# foldl :: (b -> a -> b) -> b ->ZipList a -> bSource# foldl' :: (b -> a -> b) -> b ->ZipList a -> bSource# foldr1 :: (a -> a -> a) ->ZipList a -> aSource# foldl1 :: (a -> a -> a) ->ZipList a -> aSource# toList ::ZipList a -> [a]Source# null ::ZipList a ->BoolSource# length ::ZipList a ->IntSource# elem ::Eq a => a ->ZipList a ->BoolSource# maximum ::Ord a =>ZipList a -> aSource# minimum ::Ord a =>ZipList a -> aSource# | |
| TraversableZipListSource# | |
| Generic1ZipListSource# | |
| Eq a =>Eq (ZipList a)Source# | |
| Ord a =>Ord (ZipList a)Source# | |
| Read a =>Read (ZipList a)Source# | |
| Show a =>Show (ZipList a)Source# | |
| Generic (ZipList a)Source# | |
| typeRep1ZipListSource# | |
| typeRep (ZipList a)Source# | |
(<$>) ::Functor f => (a -> b) -> f a -> f binfixl 4Source#
An infix synonym forfmap.
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 aFunctor.
Convert from a to aMaybeInt usingMaybeStringshow:
>>>show <$> NothingNothing>>>show <$> Just 3Just "3"
Convert from an to anEitherIntIntEitherIntString usingshow:
>>>show <$> Left 17Left 17>>>show <$> Right 17Right "17"
Double each element of a list:
>>>(*2) <$> [1,2,3][2,4,6]
Applyeven to the second element of a pair:
>>>even <$> (2,2)(2,True)
(<**>) ::Applicative f => f a -> f (a -> b) -> f binfixl 4Source#
A variant of<*> with the arguments reversed.
liftA ::Applicative f => (a -> b) -> f a -> f bSource#
liftA2 ::Applicative f => (a -> b -> c) -> f a -> f b -> f cSource#
Lift a binary function to actions.
liftA3 ::Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f dSource#
Lift a ternary function to actions.
optional ::Alternative f => f a -> f (Maybe a)Source#
One or none.
Produced byHaddock version 2.17.3