Safe
A library for increasing the safety of your code, by wrapping Prelude functions that potentially crash. These functions can be used to reduce the number of unsafe pattern matches in a program. These functions can be used in conjunction with Catch.
Each unsafe function has up to four additional forms. For example, with tail:
- tail :: [a] -> [a], crashes on tail []
- tailNote :: String -> [a] -> [a], takes an extra argument which supplements the error message
- takeDef :: [a] -> [a] -> [a], takes a default to return on errors
- tailMay :: [a] -> Maybe [a], wraps the result in a Maybe
- tailSafe :: [a] -> [a], returns some sensible default if possible, [] in the case of tail
This library also introduces three brand new functions:
- at, synonym for (!!)
- lookupJust, defined as lookupJust k = fromJust . lookup k
- abort, same as error, but for a deliberate and intentional program abort