箭头化 Store comonad

Arrowizing the Store comonad

过去几周我一直在为将 monad(主要来自 mtl)移植到箭头的库做出贡献。

下面是 mtl 中的 StateT monad 的简单示例:

newtype StateT s m a = StateT { runStateT :: s -> m (a, s) }
-- arrowization -->
newtype StateTA s a b c = StateTA { runStateTA :: a (b, s) (c, s) }

"arrowizing" 过程对大多数 monad 来说并不是很痛苦,但我无法根据 Store comonad 找出我的箭头。

每次我问这个问题时,人们都会将我重定向到 Cokleisli 箭头,但是 Cokleisli Store 是否等同于我要查找的箭头?

库基于 mtl 风格的架构(每个箭头都有一个通用的 class,如 ArrowStateArrowReader 等...),我试图弄清楚 ArrowStore 中我的函数的签名是什么,但同样,我做不到。

我查看了 arrows 包,它实现了与我正在使用的库中相同的箭头,但是它们的 CoState 箭头(我听说 CoState 是 Store 的另一个名称)没有定义任何操作,所以我想作者也有这个问题。

tl;博士:

感谢 ,我找到了 Store comonad 的 "arrowized" 版本。

我的问题是我找不到 "direct form" - 正如 leftaroundabout 提到的那样 - 我的箭头。但是,如果我想要的是 Cokleisli Store 那么答案很简单(不是很正式的表示法,但你明白了):

newtype CokleisliT a w b c = CokleisliT { runCokleisliT :: a (w b) c }
newtype Store s a = Store (s -> a, s)

    Arrow a => CokleisliT a (Store s) b c
<=> Arrow a => a (Store s b) c
<=> Arrow a => a (s -> b, s) c

从这里,我们可以推导出 ArrowStore class:

的签名
class Arrow a => ArrowStore s a | a -> s where
    pos   :: a () s
    peek  :: a () b -> a s b
    peeks :: a () b -> a (s -> s) b
    seek  :: a (s, b) c -> a b c
    seeks :: a (s, b) c -> a (s -> s, b) c

至于 ,显然箭头化 (co)monad 是将其包裹在 (co)Kleisli 箭头中。

这是其他箭头的库:https://github.com/felko/atl