comonad

What would be the methods of a bi-comonad?

不羁的心 提交于 2019-12-05 16:08:56
问题 While musing what more useful standard class to suggest to this one class Coordinate c where createCoordinate :: x -> y -> c x y getFirst :: c x y -> x getSecond :: c x y -> y addCoordinates :: (Num x, Num y) => c x y -> c x y -> c x y it occured me that instead of something VectorSpace-y or R2, a rather more general beast might lurk here: a Type -> Type -> Type whose two contained types can both be extracted. Hm, perhaps they can be extracted ? Turns out neither the comonad nor bifunctors

Applicative is to monad what X is to comonad

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 14:23:55
问题 Can we solve this equation for X ? Applicative is to monad what X is to comonad 回答1: After giving it some thought, I think this is actually a backward question. One might think that ComonadApply is to Comonad what Applicative is to Monad , but that is not the case. But to see this, let us use PureScript's typeclass hierarchy: class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Apply f where apply :: f (a -> b) -> f a -> f b -- (<*>) class Apply f => Applicative f where

What would be the methods of a bi-comonad?

a 夏天 提交于 2019-12-04 01:26:57
While musing what more useful standard class to suggest to this one class Coordinate c where createCoordinate :: x -> y -> c x y getFirst :: c x y -> x getSecond :: c x y -> y addCoordinates :: (Num x, Num y) => c x y -> c x y -> c x y it occured me that instead of something VectorSpace -y or R2 , a rather more general beast might lurk here: a Type -> Type -> Type whose two contained types can both be extracted. Hm, perhaps they can be extract ed ? Turns out neither the comonad nor bifunctors package contains something called Bicomonad . Question is, would such a class even make sense,

Applicative is to monad what X is to comonad

杀马特。学长 韩版系。学妹 提交于 2019-12-04 00:42:05
Can we solve this equation for X ? Applicative is to monad what X is to comonad After giving it some thought, I think this is actually a backward question. One might think that ComonadApply is to Comonad what Applicative is to Monad , but that is not the case. But to see this, let us use PureScript's typeclass hierarchy: class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Apply f where apply :: f (a -> b) -> f a -> f b -- (<*>) class Apply f => Applicative f where pure :: a -> f a class Applicative m => Monad m where bind :: m a -> (a -> m b) -> m b -- (>>=) -- join :: m (m

Understanding why Zipper is a Comonad

南楼画角 提交于 2019-12-03 06:07:04
问题 This is a follow-up to the answer to my previous question. Suppose I need to map each item a:A of List[A] to b:B with function def f(a:A, leftNeighbors:List[A]): B and generate List[B] . Obviously I cannot just call map on the list but I can use the list zipper . The zipper is a cursor to move around a list. It provides access to the current element ( focus ) and its neighbors. Now I can replace my f with def f'(z:Zipper[A]):B = f(z.focus, z.left) and pass this new function f' to cobind

Can you define `Comonads` based on `Monads`?

一个人想着一个人 提交于 2019-12-03 04:46:34
问题 Okay, so let's say you have the type newtype Dual f a = Dual {dual :: forall r. f(a -> r)->r} As it turns out, when f is a Comonad, Dual f is a Monad (fun exercise). Does it work the other way around? You can define fmap ab (Dual da) = Dual $ \fb -> da $ fmap (. ab) fb and extract (Dual da) = da $ return id , but I do not know how to define duplicate or extend . Is this even possible? If not, what the proof there is not (is there a particular Monad m for which you can prove Dual m is not a

Can you define `Comonads` based on `Monads`?

◇◆丶佛笑我妖孽 提交于 2019-12-02 17:59:12
Okay, so let's say you have the type newtype Dual f a = Dual {dual :: forall r. f(a -> r)->r} As it turns out, when f is a Comonad, Dual f is a Monad (fun exercise). Does it work the other way around? You can define fmap ab (Dual da) = Dual $ \fb -> da $ fmap (. ab) fb and extract (Dual da) = da $ return id , but I do not know how to define duplicate or extend . Is this even possible? If not, what the proof there is not (is there a particular Monad m for which you can prove Dual m is not a comonad)? Some observations: Dual IO a is essentially Void (and Const Void is a valid Comonad ). Dual m a

Lenses over Comonads or Representable

情到浓时终转凉″ 提交于 2019-11-30 17:39:19
问题 Here's a more specific variant of this question: Mutate only focus of Store Comonad?, for the benefit of not asking more than one question at once. Are there any lenses compatible with Control.Lens which allow me to interact with the focus of a comonad (the value from extract ) or with the index/value of the Store Comonad ( pos )? It seems like lenses may be of some use here, but I have been unable to find anything which fits; any help would be appreciated, thanks! 回答1: Comonad doesn't give

What is the Store comonad?

谁说胖子不能爱 提交于 2019-11-29 20:15:37
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? ehird 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 function b -> a to put a new value back into the larger context. Considering it in its simplified, non

What is the Store comonad?

喜夏-厌秋 提交于 2019-11-28 15:39:52
问题 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? 回答1: 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