framework for composing monads?

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
18 Feb 2001 12:05:13 GMT


Sun, 18 Feb 2001 15:01:18 +1100, Manuel M. T. Chakravarty <chak@cse.unsw.edu.au> pisze:

> Re (a): Usually, you have to process command line options
> etc, which also provides a natural place for
> initialization.  See, eg, the `init' function for Gtk+HS
> 
>   http://cvs.gnome.org/lxr/source/gtk%2bhs/gtk/GtkMain.chs
> 
> Clean up should really be handled by a finaliser that is
> automatically invoked before program termination,

Shutdown can be provided in the form similar to
    Socket.withSocketsDo :: IO a -> IO a
so that it still can be forgotten, but only together with
initialization, and the shutdown code may use some handles
created by initialization without using global variables.

If the initialization produces a handle which is used for all
subsequent operations (i.e. the C interface does not rely on the
global state), it can be passed as an argument to the argument to this
function and used explititly each time - but this time wrapping the
whole thing in a monad makes more sense, as it saves the programmer
from passing the handle explicitly.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK