gpt4 book ai didi

scala - 函数式编程中的 Store Comonad 和 Representable Store Comonad 有什么区别?

转载 作者:行者123 更新时间:2023-12-01 12:08:21 24 4
gpt4 key购买 nike

Representable Store Comonad 和 Store Comonad 提供了类似的功能......我们什么时候应该使用一种而不是另一种,有什么好处?

最佳答案

作为引用,以下是它们是什么的快速回顾:

class {- ... => -} Representable f where
type Key f
-- ...

data RepStore f a = RepStore (Key f) (f a)
data Store s a = Store s (s -> a)

请注意,特别是

instance Representable (s -> a) where
type Key (s -> a) = s
-- ...

所以我们直接得到了 Store sRepStore (s ->)几乎完全可以互换。另一方面,范畴论告诉我们所有 Representable仿函数与函数同构(以 Key 作为域),因此 RepStore fStore (Key f ->)是同构的。

总结:在大多数情况下,选择哪个并不重要。如果你打算只在函数上使用它,你不妨使用 Store并受益于其语法的简洁性;如果你想使用一些不完全是函数的可表示仿函数(比如,内存函数或类似的东西),那么 RepStore是一个适当的概括。

关于scala - 函数式编程中的 Store Comonad 和 Representable Store Comonad 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54368676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com