Re: Green Card and Exceptions

2003-06-13 Thread Alastair Reid
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
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Green Card and Exceptions

2003-06-13 Thread Matthew Donadio
Alastair Reid wrote:
 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.

OK, I think I misread the manual.  Sect 7.6 talks about functions with
side effects, so I assumed that the function had to have type (IO a) to
use %fail. 
 
 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?]

In the case of what I am doing, I'm not sure if IOError really make
sense philosophically.  The failures I need are underflow, overflow,
loss of precision, etc.  Since IOError is a type synonym for
IOException, then perhaps accepting an Exception constructor is
appropriate.

To keep compatibility with old libraries it may be wise to keep %fail as
is, and have a new directive %throw that accepts an Exception
constructor, and uses either throw or throwIO.

On the other hand, now that I know that I can use %fail with pure
functions, I can make that work.
 
 As GreenCard maintainer, I've got to ask:
 - How many users of GreenCard are still out there?

New GreenCard user.  In my case, I need access to C land for typedefs
and macros.  I could write my own stubs, but GreenCard saves me this
step.

 - Are you developing new libraries or just maintaining the ones you've got?

New library.

 - Is there a demand for new features?

A more generic %fail mechanism?

Thanks for the response.

-- 
Matthew Donadio ([EMAIL PROTECTED])
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe