[Haskell-cafe] Re: Control.Monad.Cont fun

Thomas Jäger thjaeger at gmail.com
Sat Jul 23 09:41:03 EDT 2005


Sorry, I have to do a small correction to an earlier post of mine.

On 7/9/05, I wrote:
> In order to move the function (\jmp -> jmp `runC` jmp) into callCC,
> the following law, that all instances of MonadCont seem to satisfy, is
> very helpful.
> f =<< callCC g === callCC (\k -> f =<< g ((=<<) k . f))
This law is in fact only satisfied for some monads (QuickCheck
suggests Cont r and ContT r m). A counterexample for the reader

  type M = ReaderT Bool (Cont Bool)

  f :: a -> M Bool
  f _ = ask

  g :: (Bool -> M a) -> M a
  g k = local not $ k True

  run :: M Bool -> Bool
  run (ReaderT m) = m True `runCont` id

  run (f =<< callCC g)  ==> True
  run (callCC (\k -> f =<< g ((=<<) k . f)))  ==> False

> In particular (regarding Functor as superclass of Monad), it follows
> f `fmap` callCC g === callCC (\k -> f `fmap` g (k . f))
This law (the one I actually used) is satisfied (again, only according
to QuickCheck) by every monad I checked.


More information about the Haskell-Cafe mailing list