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

Ertugrul Soeylemez es at ertes.de
Thu Sep 9 00:54:49 EDT 2010

Gregory Crosswhite <gcross at phys.washington.edu> wrote:

>  On 09/08/10 19:14, Ertugrul Soeylemez wrote:
> > Have you looked at ContT from monadLib?  It's not just a goto, but
> > in fact a setjmp/longjmp, i.e. a goto with value.  I haven't used it
> > for anything yet, but it might come in handy for some algorithms:
> >
> > [...]
> Whoa, that's cool!  I glanced at monadLib but I didn't realize that it
> let you create labels that you could return to like that.  :-) (I know
> of callCC, but that isn't quite the same as this.)  Thanks for the
> pointer!

It is, in fact, callCC. ;)

> The limitation with continuation-based approaches to goto, though, is
> that you can only jump back to points that you've seen before.  The
> reason why I don't use a continuation-based approach in GotoT is
> because I wanted the user (i.e., me, and maybe one or two other people
> if I'm lucky :-) ) to be able to jump to an arbitrary point outside
> the calculation that has never been visited before, rather than
> returning a previously visited point of the same calculation.
> Of course, if someone can prove to me that I am wrong and that GotoT
> semantics can be implemented with continuations, then I would welcome
> this information.  :-)

I don't think you need 'goto' to implement jumps in Haskell.  Note that
functions as well as computations are first class:

  myComp :: ContT () IO ()
  myComp = do
    input <- inBase $ putStrLn "Print something (y/n)?" >> getLine
    unless ("y" `isPrefixOf` input) exit
    inBase $ putStrLn "Something."

    input <- inBase $ putStrLn "Print more (y/n)?" >> getLine
    unless ("y" `isPrefixOf` input) exit
    inBase $ putStrLn "More."

      exit = do
        inBase $ putStrLn "Ok, I'm exiting."
        abort ()

You can interpret 'exit' as a label.  Binding can be interpreted as a


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list