[Haskell] ANN: Safe library, 0.1
Neil Mitchell
ndmitchell at gmail.com
Tue Nov 14 14:39:58 EST 2006
Hi,
I am hereby releasing the Safe library, 0.1.
http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#safe
(darcs repo, haddock documentation, cabal file, BSD3 licensed)
People often have a problem with pattern match errors, and the only
helpful message they get is: "pattern match error, head []". The Safe
library hopes to eliminate some of the frustration this causes.
Within the Safe library there are 3 different forms of head:
headNote - takes an extra parameter which gives extra information -
such as the function that is calling head, or a useful reminder to the
programmer why head might be failing.
headDef - takes an extra parameter being the default value, to return
on the empty list.
headMay - wrap the result in a Maybe, returning Nothing for failure.
There are also a large number of other wrapped functions, which may
prove useful.
A variant of this library has been in use one of my projects (Catch)
for some time, and has saved a lot of debugging headaches. I have
found an effective way of debugging is to use the normal head
function, and then when an error occurs start replacing instances of
head with headNote until the error is diagnosed. Once the headNote's
have been inserted, leave them, to help next time.
Any comments or suggestions are welcome.
Thanks
Neil
More information about the Haskell
mailing list