Closed joachifm closed 12 years ago
hmatrix has a facility for errors to be handled by Haskell (Control.Exception) so that ghci does not abort:
Numeric.GSL.setErrorHandlerOff
-- | This action removes the GSL default error handler (which aborts the program), so that -- GSL errors can be handled by Haskell (using Control.Exception) and ghci doesn't abort. foreign import ccall unsafe "GSL/gsl-aux.h no_abort_on_error" setErrorHandlerOff :: IO ()
I prefer catching exceptions to changing the return type of all functions to Either
.
Ok, that works for me. I still think it's surprising that ostensibly pure code can crash the program,
but I see your point about Either
.
Thanks.
Currently, the default GSL error handler is invoked whenever an error occurs (wrong input, etc), causing the program to crash. Instead, the API should allow the user to handle errors on the Haskell side.
A straightforward approach is to wrap calls to C in a function that explicitly disables the error handler (
gsl_set_error_handler_off
) and checks the return code, wrapping the result inEither
.