How to read Haskell `ap zip tail` to indicate` \ x & # 8594; zip x (tail x) `?

The previous question discussed how the type of a Haskell expression ap zip tailcan be translated into a type \x -> zip x (tail x). It was instructive, but neither the question nor the answer there concerned why the first expression gives the same results as the last expression, only that their types are equivalent. As far as I know, this could mean \x -> zip x (tail (tail x))instead.

I tried to read the ap documentation but didn't get it anywhere. How to read apto understand what ap zip tailgives the same results as \x -> zip x (tail x)?

+4
source share
2 answers

First, look at the source :

ap m1 m2          = do { x1 <- m1; x2 <- m2; return (x1 x2) }
-- Since many Applicative instances define (<*>) = ap, we
-- cannot define ap = (<*>)

( ), , , (->) [a]. , ap (<*>),

instance Applicative ((->) a) where
    pure = const
    (<*>) f g x = f x (g x)

(<*>) zip tail x = zip x (tail x), x zip <*> tail = \x -> zip x (tail x).

ap instance Monad (->) a , <*>, .

, , \x → zip x (tail (tail x)).

: m (a -> b) -> m a -> m b is (c -> (a -> b)) -> (c -> a) -> (c -> b) , ap f1 f2 f2 : c -> a f2 (f2 <anything>) typecheck.

+7

. , <*> ap, Applicative, Monad, Applicative.

+1

All Articles