|Copyright||(c) 2013 Joachim Breitner|
|Maintainer||Joachim Breitner <email@example.com>|
To avoid space leaks and unwanted evaluation behaviour, the programmer might want his data to be fully evaluated at certians positions in the code. This can be enforced, for example, by ample use of Control.DeepSeq, but this comes at a cost.
Experienced users hence use
deepseq only to find out about the existance of space leaks and optimize their code to not create the thunks in the first place, until the code no longer shows better performance with
This module provides an alternative approach: An explicit assertion about the evaluation state. If the programmer expect a certain value to be fully evaluated at a specific point of the program (e.g. before a call to
writeIORef), he can state that, and as long as assertions are enabled, this statement will be checked. In the production code the assertions can be disabled, to avoid the run-time cost.
assertNF checks whether its argument is fully evaluated and
deeply evaluated. If this is not the case, a warning is printed to the standard output,
giving the number of thunks found and printing the shape of the unevaluated object:
> let x = 1 + 2 > let y = (x,x) > assertNF y Parameter not in normal form: 2 thunks found: let t1 = _bco in (t1,t1) > x 3 > assertNF y >
In order to better identify the source of error messages from
assertNF, this variant allows you to include a name that is printed in the output:
> assertNFNamed "y" y y not in normal form: 2 thunks found: let t1 = _bco in (t1,t1)
This function, when called as
$assertNFHere in a module with
-XTemplateHaskell enabled, will cause the current filename and position be included in the error message:
Parameter at Test.hs:18:1 not in normal form: 2 thunks found: let t1 = _bco in (t1,t1)
Invoke this function at the top of your
main method to turn every call
assertNF and its variants to noops.