[Haskell-cafe] Callback functions?

Hugh Perkins hughperkins at gmail.com
Mon Jul 2 18:26:47 EDT 2007


This sounds something like using a continuation function.

In imperative languages, we might have something like:

class MyDisplayForm
{
   void ButtonGo_Press()
   {
       Processor.Go( new CallbackDelegate( this.SetStatus ) );
   }

   public void SetStatus( string message )
   {
      StatusLbl.Text = message;
      Application.DoEvents();
   }
}


So: we call Processor.Go, passing in a pointer to the function SetStatus (a
"delegate" in C# terminology, an "interface" in Java, a pointer in C, ...).

The Processor.Go function is going to update the status bar in MyDisplayForm
as it goes along with useful messages "Processing blah.txt...", etc.

It does that by calling the passed in "callback" function, with the
appropriate status message as a parameter.

This is also implicit to the Observer pattern, which may or may not be
useful in FP (?)


Anyway, so the question is: how do we write callback functions in
FP/Haskell?  Can someone provide a simple, but functional example?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070703/32220329/attachment.htm


More information about the Haskell-Cafe mailing list