Modulesafe-0.3.21Haskell2010
Safe
A module wrapping Prelude/Data.List functions that can throw exceptions, such as head and !!.
Each unsafe function has up to five variants, e.g. with tail:
tail :: [a] -> [a], raises an error ontail [], as provided byPrelude.tailErr :: [a] -> [a], alias fortailthat doesn't trigger anx-partialwarning and does raise errors.tailMay :: [a] -> Maybe [a], turns errors intoNothing.tailDef :: [a] -> [a] -> [a], takes a default to return on errors.tailNote :: Partial => String -> [a] -> [a], takes an extra argument which supplements the error message.tailSafe :: [a] -> [a], returns some sensible default if possible,[]in the case oftail.
All functions marked with the Partial constraint are not total, and will produce stack traces on error, on GHC
versions which support them (see GHC.Stack).
This module also introduces some new functions, documented at the top of the module.
- 91 values
- Packagesafe-0.3.21
- Exports91
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSafe.hs
New functions
6 declarationsSynonym for !!, but includes more information in the error message.
lookupJust key = fromJust . lookup keyfindJust op = fromJust . find opelemIndexJust op = fromJust . elemIndex opfindIndexJust op = fromJust . findIndex opPartial functions
2 declarationsIdentical to tail, namely that fails on an empty list.
Useful to avoid the x-partial warning introduced in GHC 9.8.
tailErr [] = error "Prelude.tail: empty list"
tailErr [1,2,3] = [2,3]Identical to head, namely that fails on an empty list.
Useful to avoid the x-partial warning introduced in GHC 9.8.
headErr [] = error "Prelude.head: empty list"
headErr [1,2,3] = 1Safe wrappers
79 declarationstailMay [] = Nothing
tailMay [1,3,4] = Just [3,4]tailDef [12] [] = [12]
tailDef [12] [1,3,4] = [3,4]tailNote "help me" [] = error "Safe.tailNote [], help me"
tailNote "help me" [1,3,4] = [3,4]tailSafe [] = []
tailSafe [1,3,4] = [3,4]The smallest element of a list with respect to the given comparison function. The result is bounded by the value given as the first argument.
The largest element of a list with respect to the given comparison function. The result is bounded by the value given as the first argument.
The largest element of a list. The result is bounded by minBound.
The largest element of a list. The result is bounded by the value given as the first argument.
The largest element of a list. The result is bounded by maxBound.
The smallest element of a list. The result is bounded by the value given as the first argument.
Deprecated. Use foldr1May instead.
Deprecated. Use foldl1May instead.
Deprecated. Use foldl1May' instead.
readNote uses readEitherSafe for the error message.
This function provides a more precise error message than readEither from base.
Discouraged
4 declarationsNew users are recommended to use minimumBound or maximumBound instead.
New users are recommended to use minimumBound or maximumBound instead.
New users are recommended to use minimumBoundBy or maximumBoundBy instead.
New users are recommended to use minimumBoundBy or maximumBoundBy instead.