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?
Share
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
a -> Store b a; you get the value of the b field, and a functionb -> ato put a new value back into the larger context.Considering it in its simplified, non-transformer form:
i.e.
duplicatechanges thes -> ainto ans -> Store s athat just returns the “updated” place after replacing the value, andextractrestores the original a by placing the value back into the larger structure.As far as its relation to State goes, you could look at it like this: