functions <*> pure x
should do it. Import Control.Applicative
module first.
Also consider this:
Prelude Control.Applicative> [(1+),(2+)] <*> pure 4
[5,6]
Prelude Control.Applicative> [(1+),(2+)] <*> [4]
[5,6]
Prelude Control.Applicative> [(1+),(2+)] <*> [4,5]
[5,6,6,7]
Prelude Control.Applicative> [(+)] <*> [1,2] <*> [4,5]
[5,6,6,7]
Prelude Control.Applicative> (+) <$> [1,2] <*> [4,5]
[5,6,6,7]
Prelude Control.Applicative> getZipList $ ZipList [(1+),(2+)] <*> ZipList [4,5]
[5,7]
Prelude Control.Applicative> getZipList $ ZipList [(1+),(2+)] <*> pure 4
[5,6]
<$>
is just a synonym for fmap
. <*>
applies what's "carried" in the applicative functor on the left, to what's on the right, according to a certain semantics. For naked lists, the semantics is the same as list monad - make all possible combinations - apply each function from the left to each object on the right, and pure x = [x]
. For lists tagged (i.e. newtype
d) as ZipList
s, the semantics is "zippery" application - i.e. one-on-one, and pure x = ZipList $ repeat x
.