Green Card and Exceptions

Matthew Donadio m.p.donadio@ieee.org
Thu, 12 Jun 2003 22:37:25 -0400


Hi all,

I have a couple of questions about Green Card and exceptions.

I am interfaceing to the GSL to get access to a few functions, and
eventually interface all of the special functions to Haskell.  And
unlike my DSP library, and am trying to get it right the first time. :)

Below is a Green Card interface to one of the functions.

%fun airy_Ai_e :: Double -> (Double, Double)
%call (double x)
%code int rc;
%     double val;
%     double err;
%     gsl_sf_result result;
%     rc = gsl_sf_airy_Ai_e(x, GSL_PREC_DOUBLE, &result);
%     val = result.val;
%     err = result.err;
%result (double val, double err)

This definition works, but it ignores the return code from the library
function.  The various return codes are from an enum defined in a header
file.  I would like to throw a Haskell exception (one of the
ArithExceptions defined in Control.Exception) depending on the value of
"rc".

Do I need to create a new DIS for the return values (which are an enum
defined in a header), change the function to return a triplet
(var,err,rc), and then throw the exception in Haskell land?  Is there a
way I can do this directly from the GC interface?  If I have to create a
DIS, can this be shared across several modules that all need the same
functionality?

Thanks.

-- 
Matthew Donadio (m.p.donadio@ieee.org)