2016-03-24 21 views
2

demek de bileşim operasyonu (.) ait ilişkisel yasası kanıtlamak için? nasıl kanıtlanır? ve kompozisyon çalışması Haskell, sadece temel bir işlem mi yoksa kendimiz tarafından bir tane olsun? eğer öyleyse bunu nasıl başarabilirim?nasıl</p> <pre><code>f :: a -> b g :: b -> c h :: c -> d </code></pre> <p>Haskell

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

Şimdi, birleşim kanıtlamak için:

+0

http://math.stackexchange.com/questions/523906/show-that-function-compositions-are-associative – Amadan

+0

“comp fgx = f (gx)' ile, 'f' comp' g'; fg ile aynı. – Amadan

+1

[[Kaynak] (https://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Base.html#.) Bağlantısını "(.)] Nasıl uygulandığını görmek için (https://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v :.). –

cevap

4

Sen şöyle kompozisyon operatöre kendini tanımlayabilir

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 

Şimdi, lhs = rhs var. QED.

+0

Teşekkür ederim ~ @ Aadit M Shah – ren

İlgili konular