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

Gregory Crosswhite gcross at phys.washington.edu
Fri Sep 3 21:12:01 EDT 2010


 People want to believe that Haskell is a better language than C, but
how could this possibly be true when Haskell lacks the very basic "goto"
feature???  If the world is going to take Haskell seriously, then this
serious blight needs to be addressed immediately!  Thus I proud to
present to you the "GotoT-transformers" package which provides this
missing functionality and so finally makes Haskell a serious contender
with C.

On a more serious note, there are times when it can be useful to not
only abort a computation in the middle, but to then transfer the flow of
execution to another computation:

do [...stuff...]
     when condition1 $ goto x
     [...more stuff...]
     when condition2 $ goto y
     [...more stuff...]
     when condition3 $ goto z

Towards this end, I developed this package which provides a GotoT monad
transformer and a "goto" function that takes a monadic computation and
returns a monadic value that has the effect of transferring control to
the new computation.  Obviously this functionality can be abused, but
when it is the natural fit I believe that it is much better to use it
directly then to go through all sorts of contortions resulting in uglier
code just to avoid it on principle.

The best implementation I could think of was to use a "trampoline"
approach.  The GotoT monadic transformer is represented by a type which
contains (wrapped inside the inner monad) either a pure value or a
monadic computation.  The runGotoT function operates by returning the
value if it is pure, and evaluating the monadic computation and feeding
the result back into itself otherwise.  The "trampoline" term refers to
the fact that the flow of execution bounces back to the runGotoT
function as long as the computation keeps calling the "goto" function.

I hope that the community not only finds this functionality useful, but
also that does not kill me for committing the egregious act of bringing
"goto" into the Haskell world.

Cheers,
Greg



More information about the Haskell-Cafe mailing list