Copyright | (c) 2014, Andrew G. Seniuk |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Andrew Seniuk <rasfar@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Pattern datatype
Note that only WR
, TR
and PR
allow for explicit recursion.
The other PatNode
s are in leaf position when they occur in a Pattern
.
WR | Continue pattern matching descendants. |
WS | Stop recursing (nothing more forced down this branch). |
WN Int |
|
WW | Fully force ( |
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 |
TN Int [String] |
|
TW [String] | Fully force ( |
TI [String] | Don't even unwrap the constructor of this node, if it's type is in the list; otherwise behave as |
PR | Spark the pattern matching of this subtree. |
PN Int | Spark |
PW | Spark the full forcing ( |
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.
will force evaluation of rnfp
".{...}" exprexpr
to a depth of two,
provided the head of expr
is a ternary constructor; otherwise it behaves
as
(i.e. do nothing).rnfp
"#" expr
will force it to only a depth of one. That is,
rnfp
".{###}" expr
when the head of rnfp
".{###}" expr = rnfp
"." exprexpr
is a ternary constructor; otherwise it won't perform any evaluation.
.rnfp
"*" expr = rnf
expr
will rnfp
".{***}" exprrnf
(deep) any ternary constructor, but
will not touch any constructor of other arity.
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 (rnfp
".{..{*.}.}" exprrnf
), but not the right.
will unwrap (shallow rnfp
".{.*:T{}#}" exprseq
) 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.
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).rnfp
".{=**}" expr
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.
compilePat :: String -> Pattern Source
showPat :: Pattern -> String Source
Inverse of compilePat
.
showPat
.compilePat
patstring = patstring
provided that
succeeds. (And, only up to
subpatterns elided from # (compilePat
patstringWI
or TI
) or from * (WW
, WN
,
TW
, TN
, PW
or PN
) nodes.)