简体   繁体   中英

Proving Composition Applicative law for ((->) r) type

The Composition Applicative Law is as follows:

pure (.) <*> u <*> v <*> w = u <*> (v <*> w)

Here's my attempt at proving the Composition law for the ((->) r) type:

RHS:

u <*> (v <*> w)
u <*> ( \y -> v y (w y) )
\x -> u x ( (\y -> v y (w y)) x )
\x -> u x ( v x (w x)) -- (A)

LHS:

pure (.) <*> u <*> v <*> w
const (.) <*> u <*> v <*> w
(\f -> const (.) f (u f)) <*> v <*> w
(\f -> (.) (u f)) <*> v <*> w
(\g -> (\f -> (.) (u f)) g (v g)) <*> w
\x -> (\g -> (\f -> (.) (u f)) g (v g)) x (w x)
-- Expanding labmda by applying to x
\x -> ((\f -> (.) (u f)) x (v x)) (w x)
\x -> (( (.) (u x)) (v x)) (w x)

\x -> ((u x) . (v x)) (w x) -- (B)

I don't think (A) & (B) are equivalent, so where did I make a mistake? I would appreciate any help or suggestions.

You're almost there. You just need to use the definition of (.) , which is

(f . g) x = f (g x)

After substituting that definition in the last line of your LHS calculation, you should have two obviously equal lambdas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM