Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Last active August 29, 2015 14:13
Show Gist options
  • Save tokiwoousaka/193ad9176e6dbd6b2362 to your computer and use it in GitHub Desktop.
Save tokiwoousaka/193ad9176e6dbd6b2362 to your computer and use it in GitHub Desktop.
モナド則: (m >>= g) >>= h == m >>= (\x -> g x >>= h)
定義: f >=> g == \x -> f x >>= g
命題:(f >=> g) >=> h == f >=> (g >=> h)
(f >=> g) >=> h
== (\x -> f x >>= g) >=> h -- (>=>)の定義
== \y -> (\x -> f x >>= g) y >>= h -- (>=>)の定義
== \y -> (f y >>= g) >>= h
== \y -> f y >>= (\z -> g z >>= h) -- モナド則
== \y -> f y >>= (g >=> h) -- (>=>)の定義
== f >=> (g >=> h) -- (>=>)の定義
よって (f >=> g) >=> h == f >=> (g >=> h)
Q.E.D.
@cobodo
Copy link

cobodo commented Jan 16, 2015

L8は
== (\y -> (f y >>= g)) >>= h
のように思うのですが、ここからダイレクトにL9への展開はできないのではないでしょうか?

@tokiwoousaka
Copy link
Author

どちらかというとL6に間違いがあったので直しました。
L6からL7へ、(>=>)の定義による変換をご確認ください。ラムダ項 (\x -> f x >>= g) を一旦Xと置くとわかり良いかと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment