ANN: H98 FFI Addendum 1.0, Release Candidate 7

Ross Paterson ross@soi.city.ac.uk
Thu, 19 Sep 2002 14:23:02 +0100


On Thu, Sep 19, 2002 at 10:28:36PM +1000, Manuel M T Chakravarty wrote:
> Ross Paterson <ross@soi.city.ac.uk> wrote,
> 
> > On Thu, Sep 19, 2002 at 12:03:34AM +1000, Manuel M T Chakravarty wrote:
> > > RC 7 of the FFI Addendum is now available from
> > > 
> > >   http://www.cse.unsw.edu.au/~chak/haskell/ffi/
> > 
> > Must it include unsafePerformIO?
> 
> Sometimes you have a C function that is pure (and hence, you
> want to give it a pure type), but as C cannot return complex
> structures as a function result, you need to allocate a
> piece of memory, pass a pointer to the C function, and read
> the result out of that memory area on return of the C
> function.  All this marshaling business requires IO actions;
> however, it doesn't change the pureness of the overall
> function.  So, you typically want to unsafePerformIO the
> marshaling business.

If the FFI stuff were available with ST variants, and foreign functions of
this sort could be declared with ST return types, would it be possible to
replace unsafePerformIO in such cases with runST?  I'm not suggesting that
the FFI spec should do this now, but if there's a clean alternative on
the horizon perhaps it would be premature to surrender to unsafePerformIO.

It also bothers me that though the spec says that the argument to
unsafePerformIO must be free of side-effects and independent of the
environment, there's no definition of which combinations of the other
functions satisfy this requirement.  (ST-based types would do this,
though.)