モナモナ言うモナド入門.tar.gz

2,120 views
1,918 views

Published on

「モナモナ言うモナド入門」の短縮版。

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,120
On SlideShare
0
From Embeds
0
Number of Embeds
197
Actions
Shares
0
Downloads
9
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

モナモナ言うモナド入門.tar.gz

  1. 1. モナモナ言う モナド入門.tar.gz 2012-11-18 hiratara
  2. 2. 100分で話して来た
  3. 3. 超短縮版
  4. 4. 話す内容• 抽象化オタクの更なる高みを目指す• 「モナドは自己関手の圏のモノイド」 という雑学
  5. 5. 大統一理論2
  6. 6. お題Monoid則とMonad則は統一できるか?
  7. 7. そのとき Philip Wadlerの脳裏に閃光が走った! ※この話はフィクションです
  8. 8. モノイダル圏双関手□と自然同型α、λ、ρがある圏 A B A□B f g f□g A’ B’ A’□B’
  9. 9. (モノイダル圏の) モノイド η□M M□η I□M M□M M□I μ λ ρ α M□μ M□M(M□M)□M M□(M□M) M μ□M μ M□M M
  10. 10. Monoid a(1) prod (id, mappend’)(a, a), a ((x, y), z) -> (x, (y, z)) a, (a, a) (a, a) prod (mappend’, id) mappend’ mappend’ (a, a) prod (f, g) (x, y) = (f x, g y) a mappend’ = uncurry mappend
  11. 11. Monoid a(1) (x <> y) <> z = x <> (y <> z) prod (id, mappend’)(a, a), a ((x, y), z) -> (x, (y, z)) a, (a, a) (a, a) prod (mappend’, id) mappend’ mappend’ (a, a) prod (f, g) (x, y) = (f x, g y) a mappend’ = uncurry mappend
  12. 12. Monoid a(2) prod (mempty’, id) prod (id, mempty’)((), a) (a, a) (a, ()) mappend’ snd fst a mempty’ = const mempty
  13. 13. Monoid a(2) mempty <> x = x x <> mempty = x prod (mempty’, id) prod (id, mempty’)((), a) (a, a) (a, ()) mappend’ snd fst a mempty’ = const mempty
  14. 14. Monoid a(2) mempty <> x = x x <> mempty = x prod (mempty’, id) prod (id, mempty’)((), a) (a, a) (a, ()) mappend’ snd fst a ”集合” mempty’ = const mempty
  15. 15. Monoidは 集合圏のモノイド
  16. 16. モナド則• 以下と同値 join . fmap join = join . join join . fmap return = join . return = id• 証明は http://ja.wikibooks.org/wiki/Haskell/ %E5%9C%8F%E8%AB%96 を参照
  17. 17. Monad m(1) id fmap joinmmma mmma mma join join joinmma ma
  18. 18. Monad m(1) join . fmap join = join . join id fmap joinmmma mmma mma join join joinmma ma
  19. 19. Monad m(2) return fmap returnma mma ma join id id ma
  20. 20. Monad m(2) join . fmap return = id join . return = id return fmap returnma mma ma join id id ma
  21. 21. Monad m(2) join . fmap return = id join . return = id return fmap returnma mma ma join id id ma ”自己関手”
  22. 22. Monadは自己関手圏のモノイド
  23. 23. まとめ• 同じ図で法則をまとめれるのはイイ• 書きかけの検証用ソース https://gist.github.com/4104020

×