[Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

Keean Schupke k.schupke at imperial.ac.uk
Mon Nov 8 14:17:38 EST 2004


>Any C library which requires an explicit initialisation call before anything
>in that library can be used (common enough IME). Accidental re-initialisation
>(e.g. by two independent modules/libraries) will destroy any state currently
>be used by the libraries existing "clients".
>
>The need to do this may or may not indicate "bad design" on the part of the
>library author. But so what? It just happens to be a fact that must be dealt
>with from Haskell (in a safe manner preferably).
>  
>
You are right, the C library that works like this is "bad design"...
any library should really be reentrant, an preferably state free.
An example of a well designed C library is the ODBC database
connection library, where all the state is stored in opaque
handles returned to the user.

For 'broken' libraries that cannot support multiple simultaneous
contexts, it would be better to use the 'C' FFI based solution
suggested by another poster. Ideally you would want to find
a library with a better interface - If you tell me the library you
wish to use I may be able to suggest a better alternative.

    Keean.


More information about the Haskell-Cafe mailing list