LambdaHack-0.2.8: A roguelike game engine in early and active development

Safe HaskellNone



Tools for specifying assertions. A step towards contracts. Actually, a bunch of hacks wrapping the original assert function, which is the only easy way of obtaining source positions.



assert :: Bool -> a -> a

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.

blame :: Show a => Bool -> a -> BoolSource

If the condition fails, display the value blamed for the failure. Used as in

 assert (c /= 0 `blame` c) $ 10 / c

failure :: Show a => (Bool -> b -> b) -> a -> bSource

Like error, but shows the source position and also the value to blame for the failure. To be used as in:

 assert `failure` ((x1, y1), (x2, y2), "designate a vertical line")

allB :: Show a => (a -> Bool) -> [a] -> BoolSource

Like 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])

skip :: Monad m => m ()Source

To be used in place of the verbose skip, as in:

 do b <- getB a
    assert (b `blame` a) skip