In Haskell, the default implementation of the (<*>)
operator (it applies an applicative of functions a->b
to an applicative of a
resulting in an applicative of b
) in Control.Applicative is defined as such-
(<*>) :: f (a -> b) -> f a -> f b
(<*>) = liftA2 id
and I simply can't understand how it works.
liftA2
has the type liftA2 :: (a -> b -> c) -> f a -> f b -> f c
, meaning it takes a binary function, which id
is not. From my understanding, this means id
is somehow interpreted as some more complex type- but I'm not sure which or how it makes this definition work. If someone could explain perhaps what type is id
interpreted as (what type the a
in the id :: a -> a
definition stands for) and also walk through how it results in a function which takes an applicative of functions and an applicative of values and applies them I would be very thankful.
->
is right associative.a -> b -> c
meansa -> (b -> c)
. – melpomene($)=id
, only with a less general type. That code can be written more clearly asap = liftA2 ($)
. – chi