箭头化商店comonad

时间:2016-10-10 15:32:54

标签: haskell category-theory arrows comonad

过去几周我一直在为一个将monad(主要是从mtl)移植到箭头的图书馆做出贡献。

以下是来自StateT的{​​{1}} monad的快速示例:

mtl

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

每当我提出这个问题时,人们都会将我重定向到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) } 箭头,但Cokleisli会等同于我正在寻找的箭头吗?

库基于Cokleisli Store式架构(每个箭头都有一般类,如mtlArrowState等......),我试图找出什么将是ArrowReader中我的职能的签名,但我再也不能。

我看了ArrowStore包,它实现了与我正在处理的库中相同的箭头,但是他们的arrows箭头(我听说CoState是Store的另一个名称)定义了no操作,所以我猜作者也遇到了这个问题。

TL; DR:

  • CoState是否等同于箭头版Monad m => Kleisli m a b
  • 对于带有m箭头的comonads也是如此吗?
  • 如果是这样,我怎样才能将Cokleisli comonad表示为箭头?
  • 如果没有,我们甚至可以“箭头化”comonads吗?

1 个答案:

答案 0 :(得分:4)

感谢leftaroundabout's comment,我找到了"箭头" Store comonad的版本。

我的问题是我无法找到"直接表格" - 正如左边提到的那样 - 我的箭头。但是,如果我想要的是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 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

对于user's comment,显然箭头化(co)monad将其包裹在(co)Kleisli箭头中。

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