简体   繁体   English

((->)r)类型的适用法律

[英]Applicative Laws for the ((->) r) type

I'm trying to check that the Applicative laws hold for the function type ((->) r) , and here's what I have so far: 我正在尝试检查适用法律是否适用于函数类型((->) r) ,这是到目前为止的内容:

-- Identiy
pure (id) <*> v = v 
-- Starting with the LHS
pure (id) <*> v
const id <*> v
(\x -> const id x (g x))
(\x -> id (g x))
(\x -> g x)
g x
v


-- Homomorphism
pure f <*> pure x = pure (f x)
-- Starting with the LHS
pure f <*> pure x
const f <*> const x
(\y -> const f y (const x y))
(\y -> f (x))
(\_ -> f x)
pure (f x)

Did I perform the steps for the first two laws correctly? 我是否正确执行了前两个法律的步骤?

I'm struggling with the interchange & composition laws. 我正在努力应对互换和排版法律。 For interchange, so far I have the following: 对于交换,到目前为止,我有以下内容:

-- Interchange
u <*> pure y = pure ($y) <*> u
-- Starting with the LHS
u <*> pure y
u <*> const y
(\x -> g x (const y x))
(\x -> g x y)
-- I'm not sure how to proceed beyond this point.

I would appreciate any help for the steps to verify the Interchange & Composition applicative laws for the ((->) r) type. 对于验证((->) r)类型的互换和组成适用法律的步骤,我将不胜感激。 For reference, the Composition applicative law is as follows: 供参考,构成适用法律如下:

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

I think in your "Identity" proof, you should replace g with v everywhere (otherwise what is g and where did it come from?). 我认为在“身份”证明中,应在任何地方用v替换g (否则g是什么,它是从哪里来的?)。 Similarly, in your "Interchange" proof, things look okay so far, but the g that magically appears should just be u . 同样,到目前为止,在“交换”证明中,一切看起来还不错,但神奇出现的g应该只是u To continue that proof, you could start reducing the RHS and verify that it also produces \\x -> uxy . 要继续证明,您可以开始降低RHS并验证它还会产生\\x -> uxy

Composition is more of the same: plug in the definitions of pure and (<*>) on both sides, then start calculating on both sides. 组成更相同:在两侧插入pure(<*>)的定义,然后在两侧开始计算。 You'll soon come to some bare lambdas that will be easy to prove equivalent. 您很快就会遇到一些简单的lambda,它们很容易证明是等效的。

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

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