deepseq-bounded-0.5.4: Bounded deepseq, including support for generic deriving

Copyright(c) 2014, Andrew G. Seniuk
LicenseBSD-style (see the file LICENSE)
MaintainerAndrew Seniuk <rasfar@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Control.DeepSeq.Bounded.Pattern

Contents

Description

 

Synopsis

Pattern datatype

data PatNode Source

Note that only WR, TR and PR allow for explicit recursion. The other PatNodes are in leaf position when they occur in a Pattern.

Constructors

WR

Continue pattern matching descendants.

WS

Stop recursing (nothing more forced down this branch).

WN Int

rnfn n the branch under this node.

WW

Fully force (rnf) the whole branch under this node.

WI

Don't even unwrap the constructor of this node.

TR [String]

Match any of the types in the list (and continue pattern matching descendants); behave as WI for nodes of type not in the list. (Note this behaviour is the complement of TI behaviour.)

TN Int [String]

rnfn n the branch under this node, if the node type matches any of the types in the list.

TW [String]

Fully force (rnf) the whole branch under this node, if the node type matches any of the types in the list; otherwise behave as WI.

TI [String]

Don't even unwrap the constructor of this node, if it's type is in the list; otherwise behave as WR. (Note this behaviour is the complement of TR behaviour.)

PR

Spark the pattern matching of this subtree.

PN Int

Spark rnfn n of this subtree.

PW

Spark the full forcing (rnf) of this subtree.

Pattern DSL

Grammar

pat -> [ = ] . [ { { pat } } ]
    |  ( [ = ] * [ decimalint ] | # )
    |  .: ctorname { space ctorname } { [ { pat } ] }
    |  ( * [ decimalint ] | # ) : typename { space typename } {}
typename -> string
ctorname -> string
decimalint -> digit string not beginning with zero
space -> space character ASCII 0x32

[I regret that Haddock cannot offer better markup for distinguishing the metasyntax. The bold is not bold enough. The alternation symbol, although /|/ in the document comment, does not show as slanted for me. Had no luck using color, also Unicode support seems pretty sketchy. Embedding an image is possible via data URL, but this has been known to crash Haddock except for very small images.]

Examples

".{...}" will match any ternary constructor.

rnfp ".{...}" expr will force evaluation of expr to a depth of two, provided the head of expr is a ternary constructor; otherwise it behaves as rnfp "#" expr (i.e. do nothing).

rnfp ".{###}" expr will force it to only a depth of one. That is, rnfp ".{###}" expr = rnfp "." expr when the head of expr is a ternary constructor; otherwise it won't perform any evaluation.

rnfp "*" expr = rnf expr.

rnfp ".{***}" expr will rnf (deep) any ternary constructor, but will not touch any constructor of other arity.

rnfp ".{..{*.}.}" expr will match any ternary constructor, then match the second subexpression constructor if it is binary, and if matching got this far, then the left sub-subexpression will be forced (rnf), but not the right.

rnfp ".{.*:T{}#}" expr will unwrap (shallow seq) the first subexpression of expr, and the third subexpression won't be touched. As for the second subexpression, if its type is T it will be completely evaluated (rnf), but otherwise it won't be touched.

rnfp ".{=**}" expr will spark the parallel complete evaluation of the two components of any pair. (Whether the computations actually run in parallel depends on resource availability, and the discretion of the RTS, as usual).

Details

The present pattern parser ignores any subpatterns of all pattern nodes except WR, TR and PR, optionally emitting a warning. Hence, only WR, TR and PR patterns are potentially recursive.

When specifying a list of subpatterns with WR or PR, in order for the match to succeed, the number of subpatterns must be equal to the arity of the named constructor.

Type constraints must always be followed by { (opening brace) as delimiter. In the case of TR, if no recursion is desired, provide {}. In order for the match to succeed, the number of subpatterns must either be zero ({}), or be equal to the arity of the named constructor.

showPat :: Pattern -> String Source

Inverse of compilePat.

showPat . compilePat patstring  =  patstring

provided that compilePat patstring succeeds. (And, only up to subpatterns elided from # (WI or TI) or from * (WW, WN, TW, TN, PW or PN) nodes.)

Why depend on whole containers package, when we only want a rose tree

data Rose a Source

Constructors

Node a [Rose a] 

Instances

Functor Rose 
Eq a => Eq (Rose a) 
Show a => Show (Rose a) 
Generic (Rose a) 
NFData a => NFData (Rose a) 
Typeable (* -> *) Rose 
type Rep (Rose a) 

Preferred to have this in Seqable, but had cyclical dependency issues