関数型プログラミング言語Haskell Part33at TECH
関数型プログラミング言語Haskell Part33 - 暇つぶし2ch241:デフォルトの名無しさん
20/04/19 01:35:32.46 WM8Q0HWB.net
[状態モナド](URLリンク(wiki.haskell.org))を
[随伴](URLリンク(en.wikipedia.org)) on Rails
に乗せてみる。
``` code
type W x a b = (a, x) -> (b, x)
type S x a b = a -> x -> (b, x)
in_away :: W x c d -> W x b c -> W x a b -> W x a d
in_away cd bc ab = cd . bc . ab
in_home :: S x c d -> S x b c -> S x a b -> S x a d
-- in_home cd bc ab = to_home $ in_away (to_away cd) (to_away bc) (to_away ab) where
-- in_home cd bc ab = ext cd . ext bc . ab where
in_home cd bc ab a = new a %>>=% ab %>>=% bc %>>=% cd where
(%>>=%) = flip ext
ext = to_home_fmap . to_away
new = to_home id
to_home_fmap = (.)
to_home = curry
to_away = uncurry
```
`to_home`が[記事](URLリンク(en.wikipedia.org))での`Phi`
に、`ext`が[Kleisliのスター](URLリンク(en.wikipedia.org))
に対応する。`in_away`は通常の関数の合成で、`in_home`はそれを黒魔術に
翻訳している。
[継続モナド](URLリンク(wiki.haskell.org))も随伴で書ける。


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch