| Copyright | Andrew G. Seniuk 2014-2015 | 
|---|---|
| License | BSD-style (see the file LICENSE) | 
| Maintainer | Andrew Seniuk <rasfar@gmail.com> | 
| Stability | provisional | 
| Portability | portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Control.DeepSeq.Bounded.NFDataN
Contents
Description
This module provides an overloaded function, deepseqn, for partially
 (or fully) evaluating data structures to a given depth.
Depth-bounded analogues of deepseq and force
deepseqn :: NFDataN a => Int -> a -> b -> b Source
 evaluates deepseqn n x yx to depth n, before returning y.
This is used when expression x also appears in y, but mere
 evaluation of y does not force the embedded x subexpression
 as deeply as we wish.
The name deepseqn is used to illustrate the relationship to seq:
 where seq is shallow in the sense that it only evaluates the top
 level of its argument,  traverses (evaluates) the entire
 top deepseqn nn levels of the data structure.
A typical use is to ensure any exceptions hidden within lazy fields of a data structure do not leak outside the scope of the exception handler; another is to force evaluation of a data structure in one thread, before passing it to another thread (preventing work moving to the wrong threads). Unlike DeepSeq, potentially infinite values of coinductive data types are supported by principled bounding of deep evaluation.
It is also useful for diagnostic purposes when trying to understand
 and manipulate space/time trade-offs in lazy code,
 and as a less indiscriminate substitute for deepseq.
Furthermore, deepseqn can sometimes be a better solution than
 using stict fields in your data structures, because the
 latter will behave strictly everywhere that its constructors
 are used, instead of just where its laziness is problematic.
There may be possible applications to the prevention of resource leaks in lazy streaming, but I'm not certain.
One of the special qualities of NFDataN is shape oblivity:
 it doesn't care about any details of the shape of the term
 it's forcing, it only cares about stratifying levels of
 recursion depth.
 (I would say "as contrasted with NFDataP" but cannot, because
 NFDataP
 was extended to include
 NFDataN
 syntax/capabilities, precisely to ammend this deficiency.)
forcen :: NFDataN a => Int -> a -> a Source
forcen is a variant of deepseqn that is useful in some circumstances.
forcen n x = deepseqn n x x
forcen n x evaluates x to depth n, and then returns it.
 Recall that, in common with all Haskell functions, forcen only
 performs evaluation when upstream demand actually occurs,
 so essentially it turns shallow evaluation into depth-n evaluation.
Class of things that can be evaluated to an arbitrary finite depth
A class of types that can be evaluated to arbitrary depth.
Minimal complete definition
Nothing
Instances