(( - >)r)类型

时间:2015-11-20 14:42:39

标签: haskell

我正在尝试检查适用法律适用于函数类型((->) 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)

我是否正确执行了前两个法律的步骤?

我正在努力解决这个问题。组成法。对于交换,到目前为止我有以下内容:

-- 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.

对于验证Interchange&amp; amp;的步骤,我将不胜感激。 ((->) r)类型的构成适用法律。作为参考,组合物适用法律如下:

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

1 个答案:

答案 0 :(得分:5)

我认为在你的身份&#34;身份&#34;证明,您应该将g替换为v到处(否则是g以及它来自哪里?)。同样,在你的&#34;交换&#34;证明,到目前为止看起来还不错,但神奇地出现的g应该只是u。要继续该证明,您可以开始减少RHS并验证它是否也生成\x -> u x y

组成更加相同:在两侧插入pure(<*>)的定义,然后开始计算双方。你很快就会找到一些容易证明等效的裸羔羊。

相关问题