什么是商店comonad? [英] What is the Store comonad?
问题描述
对 Haskell中的Comonad类型类型有一些想法 ,我听说过Store的comonad。但看看 Control.Comonad.Store.Lazy ,我真的不明白。这是什么意思?它是为了什么?我听说Store = CoState是State Monad的双重身份。这意味着什么?
如果您看一下 StoreT本身。
您可以将其视为更大结构中的地点。例如,镜头只是 a - >存储b a
;您将获得 b 字段的值,并且函数 b - >一个
把一个新值放回到更大的上下文中。
考虑到它的简化,非变换形式:
data Store sa = Store(s - > a)s
实例Functor Store s)其中
fmap f(Store gs)= Store(f。g)s
实例Extend(Store s)其中
重复(Store fs)= Store(Store f)s
实例Comonad(商店)其中
提取(商店fs)= fs
即 就它与国家的关系而言,你可以这样看待它: Having some idea of what the Comonad typeclass is in Haskell, I've heard about the Store comonad. But looking at Control.Comonad.Store.Lazy, I don't really get it. What does it mean? What is it for? I've heard that Store = CoState, the dual of the State Monad. What does that mean? It's much easier if you look at the definition of StoreT itself. You can think of it as a "place" in a larger structure. For instance, a lens is just Considering it in its simplified, non-transformer form: i.e. As far as its relation to State goes, you could look at it like this:
这篇关于什么是商店comonad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!重复
更改 s - > a
转换为 s - >在替换值后存储sa
,它只返回更新的地方,
type State sa = s - > (a,s)
类型商店s a =(s - > a,s)
a -> Store b a
; you get the value of the b field, and a function b -> a
to put a new value back into the larger context.data Store s a = Store (s -> a) s
instance Functor (Store s) where
fmap f (Store g s) = Store (f . g) s
instance Extend (Store s) where
duplicate (Store f s) = Store (Store f) s
instance Comonad (Store s) where
extract (Store f s) = f s
duplicate
changes the s -> a
into an s -> Store s a
that just returns the "updated" place after replacing the value, and extract
restores the original a by placing the value back into the larger structure.type State s a = s -> (a, s)
type Store s a = (s -> a, s)