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

余生长醉 提交于 2020-01-07 03:10:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34538754/proving-composition-applicative-law-for-r-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!