Green Card and Exceptions
Alastair Reid
alastair@reid-consulting-uk.ltd.uk
Fri, 13 Jun 2003 10:44:12 +0100
On Friday 13 June 2003 3:37 am, Matthew Donadio wrote:
> Hi all,
>
> I have a couple of questions about Green Card and exceptions.
>
> [...]
>
> 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".
The %fail statements (described in the last few paragraphs of
http://www.haskell.org/greencard/downloads/greencard-latest/type-sig.html)
consist of two C expressions. For example:
%fail {f == NULL} {errstring(errno)}
The first is a test for failure.
The second is an expression which returns a C string.
If the test expression fails, the string expression is evaluated and used to
generate a UserError.
> If I have to create a
> DIS, can this be shared across several modules that all need the same
> functionality?
It would be nice to be able to write something like:
%fail POSIX_FD(fd)
where POSIX_FD is something you defined elsewhere (e.g., it might test if its
file-descriptor argument is -1). GreenCard can't do this.
It would also be nice to be able to generate a different error instead of
UserError. We'd need to specify the type and the exception constructor so a
plausible syntax would be:
%fail {f == NULL} (UserError (string {errstring(errno)}))
[Detail: should it be a Haskell98 IOError constructor or a non-standard but
widely implemented exception constructor? Should it be a function or a
constuctor?]
Again, GreenCard can't do that.
As GreenCard maintainer, I've got to ask:
- How many users of GreenCard are still out there?
- Are you developing new libraries or just maintaining the ones you've got?
- Is there a demand for new features?
--
Alastair Reid