| Safe Haskell | None |
|---|
Control.Exception.Assert
- newtype Arse = Arse String
- assertMessage :: String -> String -> (a -> a) -> a -> a
- byEq :: (Eq x, Show x) => (Bool -> a -> a) -> String -> x -> x -> a -> a
- byOrd :: (Ord x, Show x) => (Bool -> a -> a) -> String -> Ordering -> x -> x -> a -> a
- byPred :: Show x => (Bool -> a -> a) -> String -> (x -> Bool) -> x -> a -> a
- assert :: Bool -> a -> a
Documentation
A distict Exception from AssertionFailed, so that we stop fudging
the exception message after the first mapException.
The name comes from abbreviating ‘assert’ and translating the result to my native tongue.
assertMessage :: String -> String -> (a -> a) -> a -> aSource
byEq :: (Eq x, Show x) => (Bool -> a -> a) -> String -> x -> x -> a -> aSource
Assert that two values are equal.
>>>byEq assert "Bool" False True ()*** Exception: … Assertion failed "Bool", False ≠ True
byOrd :: (Ord x, Show x) => (Bool -> a -> a) -> String -> Ordering -> x -> x -> a -> aSource
Assert that two values obey the given Ordering.
>>>byOrd assert "Int" LT 0 1 ()()
byPred :: Show x => (Bool -> a -> a) -> String -> (x -> Bool) -> x -> a -> aSource
Assert that a value satisfies the given predicate.
>>>byPred assert "Odd" odd 4 ()*** Exception: … Assertion failed "Odd", 4
If the first argument evaluates to True, then the result is the
second argument. Otherwise an AssertionFailed exception is raised,
containing a String with the source file and line number of the
call to assert.
Assertions can normally be turned on or off with a compiler flag
(for GHC, assertions are normally on unless optimisation is turned on
with -O or the -fignore-asserts
option is given). When assertions are turned off, the first
argument to assert is ignored, and the second argument is
returned as the result.