| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Howl.Pat
Description
Internal pattern representation used by the evaluator.
These patterns are compiled from Wolfram Language pattern expressions and then used during matching.
Synopsis
- data Pat
- = PatSymbol { }
- | PatLit { }
- | PatVar {
- names :: ![Symbol]
- headConstraint :: !(Maybe Symbol)
- | PatSeqVar { }
- | PatApp { }
- | PatAlt {
- names :: ![Symbol]
- missingInLeft :: ![Symbol]
- missingInRight :: ![Symbol]
- left :: !Pat
- right :: !Pat
- | PatOptional { }
- | PatCondition { }
- data PatAppType
- data SeqType
- outerNames :: Pat -> [Symbol]
- patNames :: Pat -> Set Symbol
- mapNames :: ([Symbol] -> [Symbol]) -> Pat -> Pat
- addNames :: [Symbol] -> Pat -> Pat
- matchesUniqueExpr :: Pat -> Maybe Expr
- patRootSymbol :: Pat -> Maybe Symbol
- patFromExpr :: MonadFail m => (Symbol -> m PatAppType) -> Expr -> m Pat
Documentation
TODO:
Composite Patterns - p..(Repeated), p...(RepeatedNull) - Except - Longest - Shortest - OptionsPattern, PatternSequence, Verbatim, HoldPattern - OrderlessPatternSequence - KeyValuePattern
Pattern Defaults _. (Optional) pattern with predefined default Default - predefined default arguments for a function
A compiled pattern.
Each constructor takes a list of variable names to bind to the
result of the match. We need a list because we can have nested
named patterns such as x:(y:(z:_)). If the list is empty, the
pattern is unnamed.
Constructors
| PatSymbol | A literal symbol pattern. |
| PatLit | A literal (numeric/string) pattern. |
| PatVar | A blank pattern, optionally constrained by a head symbol. |
Fields
| |
| PatSeqVar | A sequence blank ( |
| PatApp | A head application pattern with precomputed app attributes. |
| PatAlt | Alternatives, with precomputed missing names for each branch. When the left branch matches we bind missingInLeft to 'Sequence[]', and symmetrically for the right branch. |
Fields
| |
| PatOptional | An optional pattern with a default expression. |
| PatCondition | A pattern with a /; condition. |
data PatAppType #
Application-type information attached to a compiled head pattern.
This records whether the matched head should be treated as free, commutative, associative, or associative-commutative.
Instances
| Show PatAppType # | |
Defined in Howl.Pat Methods showsPrec :: Int -> PatAppType -> ShowS # show :: PatAppType -> String # showList :: [PatAppType] -> ShowS # | |
| Eq PatAppType # | |
Defined in Howl.Pat | |
| Ord PatAppType # | |
Defined in Howl.Pat Methods compare :: PatAppType -> PatAppType -> Ordering # (<) :: PatAppType -> PatAppType -> Bool # (<=) :: PatAppType -> PatAppType -> Bool # (>) :: PatAppType -> PatAppType -> Bool # (>=) :: PatAppType -> PatAppType -> Bool # max :: PatAppType -> PatAppType -> PatAppType # min :: PatAppType -> PatAppType -> PatAppType # | |
The multiplicity of a sequence pattern.
Constructors
| ZeroOrMore | |
| OneOrMore |
outerNames :: Pat -> [Symbol] #
Get names from the outer-most constructor of a Pat.
mapNames :: ([Symbol] -> [Symbol]) -> Pat -> Pat #
Map a function over the names of the outermost constructor in a
Pat.
matchesUniqueExpr :: Pat -> Maybe Expr #
Check whether a pattern matches a unique expression and introduces no bindings.
For example, Foo[12] matches a unique expression, but Foo[x_]
does not. This function is conservative and only uses syntax
information, so there may be cases where the pattern does match a
unique expression but this function does not detect it. For example,
(x_/;SameQ[x,12]) matches only 12, but this function returns
Nothing.
It is also important to reject patterns that introduce bindings because we are short-circuiting the pattern matching process, and so those bindings would not happen. TODO: we could pre-compute the bindings and store them.
patRootSymbol :: Pat -> Maybe Symbol #
Return the repeated head symbol of a pattern, if there is one.
This is used to deduce which symbol a rule should be associated with.
patFromExpr :: MonadFail m => (Symbol -> m PatAppType) -> Expr -> m Pat #
Compile a Wolfram Language pattern expression into a Pat.
The callback is used to determine the application type of head symbols while compiling application patterns.