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