简体   繁体   English

证明成分((->)r)类型的适用法律

[英]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: 这是我为((->) r)类型证明成分定律的尝试:

RHS: 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: 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? 我不认为(A)和(B)是等效的,那么我在哪里犯了错误? 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. 在将LHS定义的最后一行替换为该定义之后,您应该拥有两个明显相等的lambda。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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