Questions tagged [comonad]

The inverse of a monad. A monad is a way to structure computations in terms of values and sequences of computations using those values. Monads allow the programmer to build up computations using sequential building blocks, which can themselves be sequences of computations.

63 questions
5
votes
1 answer

How should I implement a Cayley Table in Haskell?

I'm interested in generalizing some computational tools to use a Cayley Table, meaning a lookup table based multiplication operation. I could create a minimal implementation as follows : date CayleyTable = CayleyTable { ct_name :: ByteString, …
Jeff Burdges
  • 4,204
  • 23
  • 46
5
votes
1 answer

Is this "Coapplicative" class a superclass for Comonad?

Recall the Applicative class: class Functor f => Applicative f where pure :: a -> f a liftA2 :: (a -> b -> c) -> f a -> f b -> f c (<*>) :: f (a -> b) -> f a -> f b liftA2 h x y = fmap h x <*> y (<*>) = liftA2 id Though it's…
Dannyu NDos
  • 2,458
  • 13
  • 32
5
votes
1 answer

What is a Cohoist in scalaz?

The scalaz defines a Cohoist: trait Cohoist[F[_[_], _]] extends ComonadTrans[F] { def cohoist[M[_], N[_]: Comonad](f: M ~> N): F[M, ?] ~> F[N, ?] } where ComonadTrans is defined: trait ComonadTrans[F[_[_], _]] { def lower[G[_]: Cobind,…
Valy Dia
  • 2,781
  • 2
  • 12
  • 32
5
votes
1 answer

Lenses over Comonads or Representable

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…
Chris Penner
  • 1,881
  • 11
  • 15
5
votes
2 answers

Reasonable Comonad implementations

We can describe monad, as the computational context, and monad implementation exactly preserves the meaning of that context. For example Option - the context meaning is that the value might exist. Given the Option datatype, the only implementation…
I See Voices
  • 842
  • 5
  • 13
5
votes
2 answers

Combining the state monad with the costate comonad

How to combine the state monad S -> (A, S) with the costate comonad (E->A, E)? I tried with both obvious combinations S -> ((E->A, E), S) and (E->S->(A, S), E) but then in either case I do not know how to define the operations (return, extract, ...…
Bob
  • 1,713
  • 10
  • 23
5
votes
1 answer

Are comonads a good fit for modeling the Wumpus world?

I'm trying to find some practical applications of a comonad and I thought I'd try to see if I could represent the classical Wumpus world as a comonad. I'd like to use this code to allow the Wumpus to move left and right through the world and clean…
Tim Stewart
  • 5,350
  • 2
  • 30
  • 45
4
votes
1 answer

What kind of structure is this? (Monad with a partial inverse but not a comonad)

I have encountered a structure that looks like a monad with a one-sided inverse and some additional properties. I am not sure which properties of this structure are essential and which are accidental, so I will follow a simple example in my…
AndreA
  • 295
  • 2
  • 12
4
votes
0 answers

How to change focus of a Haskell Store Comonad on a 2D list

I am strugling with the following problem. I am trying to make Game of Life using store comonads in Haskell. I have the following relevant code: type Cel = ((Float, Float), Bool) type Field2D = [[Cel]] I have then created an initial…
Thobro
  • 41
  • 2
4
votes
1 answer

Arrowizing the Store comonad

I've been contributing for a past few weeks to a library that ports monads (mainly from mtl) to arrows. Here's a quick example with the StateT monad from mtl: newtype StateT s m a = StateT { runStateT :: s -> m (a, s) } -- arrowization --> newtype…
baxbaxwalanuksiwe
  • 1,474
  • 10
  • 20
4
votes
1 answer

Unfoldable instance for the cofree comonad

I'm trying to figure out the difference between unfold/coiter from Control.Comonad.Cofree and unfold/ana from Data.Control.Fixedpoint. Hackage libraries are resp. free and recursion-schemes. Cofree and Fix seem to be cousins, and I'm trying to…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
4
votes
1 answer

Pithy summary for comonad. (Where a monad is a 'type for impure computation')

In terms of pithy summaries - this description of Monads seems to win - describing them as a 'type for impure computation'. What is an equivalent pithy (one-sentence) description of a comonad?
hawkeye
  • 34,745
  • 30
  • 150
  • 304
4
votes
1 answer

Scala comonads; Comonad laws?

So given this encoding of a comonad (see below) are the comonad laws above it correct? for some reason I don't think they are from looking at them, and I know that heading off wrong from there will yield only bad road, so I'd appreciate the nudge,…
user1888498
3
votes
2 answers

removing explicit recursion by replacing catamorphism

I have this AST data structure data AST = Integer Int | Let String AST AST | Plus AST AST | Minus AST AST | Times AST AST | Variable String | Boolean Bool | If AST AST AST |…
3
votes
1 answer

Non-empty-list comonad

I have been meditating on comonads and have an intuition that a non-empty list ("full list") is a comonad. I have constructed a plausible implementation in Idris and have worked on proving the comonad laws but have not been able to prove the…
Keith Pinson
  • 7,835
  • 7
  • 61
  • 104