bax*_*iwe 4 haskell arrows category-theory comonad
在过去的几周里,我一直在为一个将 monads(主要来自mtl)移植到 arrows的库做出贡献。
这是一个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) }
Run Code Online (Sandbox Code Playgroud)
对于大多数 monad 来说,“箭头化”过程并不是很痛苦,但我无法根据 Store comonad 找出我的箭头。
每次我问这个问题时,人们都会将我重定向到Cokleisli箭头,但将Cokleisli Store等同于我正在寻找的箭头?
该库基于一种mtl风格的体系结构(每个箭头都有一个通用类,如ArrowState、ArrowReader等...),我试图弄清楚我的函数在 中的签名是什么ArrowStore,但同样,我不能。
我查看了arrows实现与我正在研究的库中相同箭头的包,但是它们的CoState箭头(我听说 CoState 是 Store 的另一个名称)定义了没有操作,所以我猜作者也遇到了这个问题.
tl;博士:
Monad m => Kleisli m a b相当于箭头版本m?Cokleisli箭头的共生体也是如此吗?Storecomonad表示为箭头?感谢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
Run Code Online (Sandbox Code Playgroud)
从这里,我们可以推断出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
Run Code Online (Sandbox Code Playgroud)
至于用户的评论,显然箭头化 (co)monad 是将它包裹在 (co)Kleisli 箭头中。
这是其他箭头的库:https : //github.com/felko/atl。
| 归档时间: |
|
| 查看次数: |
213 次 |
| 最近记录: |