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))も随伴で書ける。