apfelmus wrote:
Luke Palmer wrote:
Isn't a type which is both a Monad and a Comonad just Identity?

(I'm actually not sure, I'm just conjecting)

Good idea, but it's not the case.

  data L a = One a | Cons a (L a)   -- non-empty list

Maybe I can entice you to elaborate slightly. From
http://www.eyrie.org/~zednenem/2004/hsce/Control.Functor.html and Control.Comonad.html there is

----------------------------------------------------------
newtype O f g a   -- Functor composition:  f `O` g

instance (Functor f, Functor g) => Functor (O f g) where ...
instance Adjunction f g         => Monad   (O g f) where ...
instance Adjunction f g         => Comonad (O f g) where ...

-- I assume Haskell can infer Functor (O g f) from Monad (O g f), which
-- is why that is missing here?

class (Functor f, Functor g) => Adjunction f g | f -> g, g -> f where
  leftAdjunct  :: (f a -> b) -> a -> g b
  rightAdjunct :: (a -> g b) -> f a -> b
----------------------------------------------------------

Functors are associative but not generally commutative. Apparently a Monad is also a Comonad if there exist left (f) and right (g) adjuncts that commute. [and only if also??? Is there a contrary example of a Monad/Comonad for which no such f and g exist?]

In the case of
>   data L a = One a | Cons a (L a)   -- non-empty list

what are the appropriate definitions of leftAdjunct and rightAdjunct? Are they Monad.return and Comonad.extract respectively? That seems to unify a and b unnecessarily. Do they wrap bind and cobind? Are they of any practical utility?

My category theory study stopped somewhere between Functor and Adjunction, but is there any deep magic you can describe here in a paragraph or two? I feel like I will never get Monad and Comonad until I understand Adjunction.

Dan

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to