Tools for specifying assertions. A step towards contracts.
Actually, a bunch of hacks wrapping the original
which is the only easy way of obtaining source locations.
- assert :: Bool -> a -> a
- blame :: Show a => Bool -> a -> Bool
- failure :: Show a => (Bool -> b -> b) -> a -> b
- allB :: Show a => (a -> Bool) -> [a] -> Bool
- checkM :: (Show a, Monad m) => (Bool -> m () -> m ()) -> (c -> Bool) -> a -> c -> m ()
- trueM :: (Show a, Monad m) => (Bool -> m () -> m ()) -> a -> Bool -> m ()
- falseM :: (Show a, Monad m) => (Bool -> m () -> m ()) -> a -> Bool -> m ()
If the first argument evaluates to
True, then the result is the
second argument. Otherwise an
AssertionFailed exception is raised,
String with the source file and line number of the
Assertions can normally be turned on or off with a compiler flag
(for GHC, assertions are normally on unless optimisation is turned on
-O or the
option is given). When assertions are turned off, the first
assert is ignored, and the second argument is
returned as the result.
If the condition fails, display the value blamed for the failure. Used as in
assert (c /= 0 `blame` c) $ 10 / c
error, but shows the source location and also
the value to blame for the failure. To be used as in:
assert `failure` ((x1, y1), (x2, y2), "designate a vertical line")
all, but if the predicate fails, blame all the list elements
and especially those for which it fails. To be used as in:
assert (allB (>= 0) [yf, xf, y1, x1, y2, x2])
Check that the value returned from a monad action satisfies a predicate. Reports source location and the suspects. Drops the value.
Verifies that the returned value is true (respectively, false). Used as in:
open newValve >>= assert `trueM` (newValve, "is already opened, not new")