Semantically identical to seq, but with a subtle operational difference: seq is strict in both its arguments, so the compiler may, for example, rearrange a `seq` b into b `seq` a `seq` b. This is normally no problem when using seq to express strictness, but it can be a problem when annotating code for parallelism, because we need more control over the order of evaluation; we may want to evaluate a before b, because we know that b has already been sparked in parallel with par.
This is why we have pseq. In contrast to seq, pseq is only strict in its first argument (as far as the compiler is concerned), which restricts the transformations that the compiler can do, and ensures that the user can retain control of the evaluation order.
This package provides methods for fully evaluating data structures ("deep evaluation"). Deep evaluation is often used for adding strictness to a program, e.g. in order to force pending exceptions, remove space leaks, or force lazy I/O to happen. It is also useful in parallel programs, to ensure pending work does not migrate to the wrong thread.
The primary use of this package is via the deepseq function, a "deep" version of seq. It is implemented on top of an NFData typeclass ("Normal Form Data", data structures with no unevaluated components) which defines strategies for fully evaluating different data types.
If you want to automatically derive NFData instances via the GHC.Generics facility, there is a companion package <http:hackage.haskell.orgpackagedeepseq-generics deepseq-generics> which builds on top of this package.
This package provides a deepseq function analogous to seq, except that it traverses the entire data structure, evaluating it fully, and not just up to head normal form.
Using lists as an example:
> > [1,2,undefined] `seq` 3
Whereas with deepseq:
> > [1,2,undefined] `deepseq` 3
> *** Exception: Prelude.undefined
Unlike the deepseq package, this implementation is based on the GHC.Generics framework as found in GHC >= 7.2, so that it can generate instances automatically for any datatype that has a Generic instance, without further code.
> data MyType = MyType String Int (Maybe Double)
> deriving Generic
> instance DeepSeq MyType
Changes in version 220.127.116.11:
* Vastly improved performance. As a consequence of these changes, the member function of the DeepSeq class is now rnf, instead of deepseq.
* New instances for functions, Ratio and Complex types.
Changes in version 18.104.22.168:
* Fix the U1 and V1 instances.
Changes in version 22.214.171.124:
* No functional changes, updated to correct the URLs of the repository and the issue tracker.
rdeepseq fully evaluates its argument.
> rdeepseq == evalSeq Control.Seq.rdeepseq