1

Assume I have

  • a comonad D
  • a monad T
  • a distributive law l : D T -> T D of the comonad D over the monad T.

How can I define the comonad D T?

Bob
  • 1,713
  • 10
  • 23
  • 3
    What makes you think that's possible? Let `D` be the identity comonad, then such a scheme would turn any monad into a comonad. – Li-yao Xia Dec 01 '19 at 15:07
  • 1
    @Li-yaoXia Because I thought it was the point of having a distributive law. So what is it useful for? – Bob Dec 01 '19 at 20:26

1 Answers1

6

You can't. Suppose D is the identity comonad and T is Cont Void, i.e. the continuation monad at the empty type.

newtype D a = D {runD :: a}
newtype T a = T {runT :: (a -> Void) -> Void}

Then distributivity holds trivially. But extract :: D (T a) -> a is not definable as a total computable program. It would be double negation elimination forall a. ((a -> Void) -> Void) -> a, which is not definable in constructive languages.

András Kovács
  • 29,931
  • 3
  • 53
  • 99
  • Great :-( So what's the point of having a distributive law if you cannot use it to derive a comonad (or a monad)? – Bob Dec 01 '19 at 20:28
  • 2
    @Bob we need distribution to compose [two comonads](https://stackoverflow.com/questions/12963733/writing-cojoin-or-cobind-for-n-dimensional-grid-type), for example. – András Kovács Dec 01 '19 at 20:42