[Haskell-cafe] Re: ANNOUNCE: GotoT-transformers version 1.0

Ertugrul Soeylemez es at ertes.de
Thu Sep 9 02:12:28 EDT 2010

Antoine Latter <aslatter at gmail.com> wrote:

> > I don't think you need 'goto' to implement jumps in Haskell.  Note
> > that functions as well as computations are first class:
> To recover from my overly complex previous post, here is a much simply
> goto based on existing monad transformers:
> > goto :: Monad m => ContT r m r -> ContT r m a
> > goto (ContT m) = ContT $ \_ ->
> >                m return
> Reading your post, Ertugrul, made something click for me

Yeah, that's a great functional CPS-based goto, which allows all kinds
of spaghetti code.  And it is in fact a real jump because of tail-call
optimization. =)

As a side note, the 'abort' function is implemented in a similar way.
It ignores the continuation and jumps to an empty computation, that way
it returns from the ContT computation.


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list