Questions tagged [applicative]

In Haskell, Applicative functors are functors such that two functorial values can be combined into one, whilst the two values inside are combined via a functional application. An applicative functor has more structure than a functor but less than a monad.

In Haskell, applicative functors are functors such that two functorial values (of type Applicative f => f a) can be combined into one, and the two values inside will be combined via a functional application (so the types "on the inside" must be compatible).

Definition

 class (Functor f) => Applicative f where
   pure  :: a -> f a                          -- injection
   (<*>) :: f (a -> b) -> f a -> f b          -- combination

The pure function lifts any value into the functor. (<*>) changes a functorial function into a function over functorial values. Applicative functor should satisfy some laws:

 pure id <*> v = v                            -- Identity
 pure (.) <*> u <*> v <*> w = u <*> (v <*> w) -- Composition
 pure f <*> pure x = pure (f x)               -- Homomorphism
 u <*> pure y = pure ($ y) <*> u              -- Interchange

And the Functor instance should satisfy the following law:

 fmap f x = pure f <*> x                      -- Fmap
572 questions
-3
votes
2 answers

Monad more powerful than Applicative?

I looked at past discussion but could not see why any of the answers are actually correct. Applicative <*> :: f (a -> b) -> f a -> f b Monad (>>=) :: m a -> (a -> m b) -> m b So if I get it right, the claim is that >>= cannot be written by only…
rapt
  • 11,810
  • 35
  • 103
  • 145
-6
votes
1 answer

Composing applicative functions

Please implement the function: composeApplicative :: (Applicative f) => f (b -> c) -> f (a -> b) -> f (a -> c) Such that: (composeApplicative f g) <*> x == f <*> (g <*> x) Or alternatively, explain why this can not be done?
Clinton
  • 22,361
  • 15
  • 67
  • 163
1 2 3
38
39