4

在过去的几周里,我一直在为一个将 monads(主要从mtl)移植到箭头的库做出贡献。

这是一个StateT来自 monad的简单示例mtl

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) }

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

每次我问这个问题时,人们都会将我重定向到Cokleisli箭头,但会Cokleisli Store等同于我正在寻找的箭头吗?

该库基于mtl-style 架构(每个箭头都有一个通用类,如ArrowState,ArrowReader等),我试图弄清楚我的函数在 中的签名是什么ArrowStore,但我还是不能。

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

tl;博士:

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

1 回答 1

5

感谢leftaroundabout的评论,我找到了comonad的“箭头化”版本Store

我的问题是我找不到箭头的“直接形式” - 正如 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 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 。

于 2016-10-10T19:47:12.673 回答