
Hi, I have a question regarding the connection between monads and comonads. I always thought of the comonad operations as being the inverse operations of the corresponding monad functions. As I do not know the underlying theory I thought I simply ask the masters. Is there a formal verification for this intuition? That is, are there always corresponding instances for monad and comonad such that the following laws are satisfied? extract . return == id join . duplicate == id If this is the case I would like to know what the corresponding monad for the following comond could be. This comonad treats lists as pointed sets where the first element is focused. instance Comonad [] where extract = head duplicate xs = init (zipWith (++) (tails xs) (inits xs)) Obviously we can define return x = [x]. But I do not know how to define join. Cheers, Jan

I have a question regarding the connection between monads and comonads. I always thought of the comonad operations as being the inverse operations of the corresponding monad functions.
That's not true.
If this is the case I would like to know what the corresponding monad for the following comond could be. This comonad treats lists as pointed sets where the first element is focused.
instance Comonad [] where extract = head duplicate xs = init (zipWith (++) (tails xs) (inits xs))
First of all, this is NOT a comonad. The term "comonad" doesn't refer just to instances of Comonad class, it refers to instances that satisfy several laws. Secondly, "[]" is a monad, and there is an instance of Monad class for it. It's working; don't fix it.

Hi, On 08.05.2009, at 13:14, Miguel Mitrofanov wrote:
I have a question regarding the connection between monads and comonads. I always thought of the comonad operations as being the inverse operations of the corresponding monad functions.
That's not true.
I thought there is some kind of duality between monads and comonads in category theory. Does this "only" refer to the types of the functions or am I totally wrong here?
If this is the case I would like to know what the corresponding monad for the following comond could be. This comonad treats lists as pointed sets where the first element is focused. instance Comonad [] where extract = head duplicate xs = init (zipWith (++) (tails xs) (inits xs))
First of all, this is NOT a comonad. The term "comonad" doesn't refer just to instances of Comonad class, it refers to instances that satisfy several laws.
I am aware of this. I thought it does satisfy all the laws. Which one have I missed?
Secondly, "[]" is a monad, and there is an instance of Monad class for it. It's working; don't fix it.
I am also aware of this. Perhaps I should have used a data type like data Pointed a = Pointed a [a] but in this case a corresponding duplicate implementation is more complicated. I am very sorry if have asked a stupid question. Cheers, Jan

Seems like I was wrong. It does satisfy comonad laws. Sorry. However, the "duality" of monads and comonads isn't that simple. A comonad is actually a monad itself, but in different category. It has nothing to do with inverse functions etc. Jan Christiansen wrote on 08.05.2009 14:47:
Hi,
I have a question regarding the connection between monads and comonads. I always thought of the comonad operations as being the inverse operations of the corresponding monad functions. As I do not know the underlying theory I thought I simply ask the masters.
Is there a formal verification for this intuition? That is, are there always corresponding instances for monad and comonad such that the following laws are satisfied?
extract . return == id
join . duplicate == id
If this is the case I would like to know what the corresponding monad for the following comond could be. This comonad treats lists as pointed sets where the first element is focused.
instance Comonad [] where extract = head duplicate xs = init (zipWith (++) (tails xs) (inits xs))
Obviously we can define return x = [x]. But I do not know how to define join.
Cheers, Jan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello Jan,
the principle of duality in category theory is not like "being the
inverse", but more like "stating the same somewhere else". To each
category there is an opposite category, which is just the same, but with
all arrows flipped. A comonad in the original category is then a monad
in the corresponding opposite category.
Greets,
Ertugrul.
Jan Christiansen
Hi,
I have a question regarding the connection between monads and comonads. I always thought of the comonad operations as being the inverse operations of the corresponding monad functions. As I do not know the underlying theory I thought I simply ask the masters.
Is there a formal verification for this intuition? That is, are there always corresponding instances for monad and comonad such that the following laws are satisfied?
extract . return == id
join . duplicate == id
If this is the case I would like to know what the corresponding monad for the following comond could be. This comonad treats lists as pointed sets where the first element is focused.
instance Comonad [] where extract = head duplicate xs = init (zipWith (++) (tails xs) (inits xs))
Obviously we can define return x = [x]. But I do not know how to define join.
Cheers, Jan
-- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/
participants (3)
-
Ertugrul Soeylemez
-
Jan Christiansen
-
Miguel Mitrofanov