a breaking monad

Derek Elkins ddarius@hotpop.com
Fri, 1 Aug 2003 06:22:57 -0400


On Fri, 1 Aug 2003 12:02:00 +0200
Tomasz Zielonka <t.zielonka@students.mimuw.edu.pl> wrote:

> On Thu, Jul 31, 2003 at 05:15:33PM -0400, Derek Elkins wrote:
> > On Thu, 31 Jul 2003 13:18:40 -0700
> > "Hal Daume" <t-hald@microsoft.com> wrote:
> > 
> > > so, my questions are: does this exist in some other form I'm not
> > > aware of?  is there something fundamentally broken about this
> > > (sorry for the pun)?  any other comments, suggestions?
> > 
> > This looks like a bizarre rendition of the Error/Exception monad.
> > 
> > I believe the function "breakable" would be fairly accurately
> > represented with '\b -> runErrorT b >>= either return return' and
> > use throwError for break.
> 
> I used the Cont(inuation) monad for similar purposes. This has an
> advantage that you can choose a place to break (jump?) into, each
> place having a possibly different type of return value.

I was thinking of providing a Cont example too.

> PS. Are there other uses of Cont monad?

I've used it for resumptions, and I imagine you could use it to handle
the CP in an "optimized" via CPS function, though that likely isn't
worthwhile (heh).  Hinze's Backtracking monad uses CPS but not the Cont
monad, though it may be representable with ContT over Cont, I'm pretty
sure shift/reset can get the same effect.

Less immediately practical, I've experimented with shift/reset with it.
I'm kind of interested in translating Filinsky's monadic reification and
reflection into Haskell with the Cont(T) monad.  This would probably
have no real practical benefit (or would it... run-time changing?), I
believe a similar effect usage-wise can be achieved by using a class for
the monad parameter (MonadState/etc.) It would be more practical if a
compiler internally supported a Cont(T) monad.

Anyways, most of my uses of the Cont monad have been for my own personal
entertainment, and usually I break the abstraction (using
Control.Monad.Cont) to do the things I want.  I don't know if I've ever
written something that's used callCC that I kept.