简体   繁体   English

如何证明Haskell中的复合运算(。)的关联定律

[英]how to prove the associative law of the compositon operation (.) in Haskell

say , 说,

    f :: a -> b 
    g :: b -> c 
    h :: c -> d

why the equation 为什么方程式

    h.(g.f) = (h.g).f  

is right? 是对的? how to prove it? 怎么证明呢? and the composition operation is just a basic operation in Haskell, or we can get one by ourselves? 合成操作只是Haskell中的基本操作,还是我们可以自己获得一个? if so how to achieve it? 如果可以的话如何实现呢?

You can define the composition operator yourself as follows: 您可以自己定义合成运算符,如下所示:

(.) :: (b -> c) -> (a -> b) -> a -> c
g . f = \x -> g (f x)

Now, to prove associativity: 现在,要证明关联性:

lhs = h . (g . f)
    = \x -> h ((g . f) x)         -- substitution
    = \x -> h ((\y -> g (f y)) x) -- substitution
    = \x -> h (g (f x))           -- beta reduction

rhs = (h . g) . f
    = \x -> (h . g) (f x)         -- substitution
    = \x -> (\y -> h (g y)) (f x) -- substitution
    = \x -> h (g (f x))           -- beta reduction

Now, we have lhs = rhs . 现在,我们有lhs = rhs QED. QED。

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

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